Skip to main content

Chapter 6b - Break

Break Statementโ€‹

for i in range(100):
print(i)
if(i==8):
break
  • Note how it stops when i==8
  • What happens if you delete the:
if(i==8):
break

?

Minerโ€‹

๐Ÿ‘€ Miners

The following program


for i in range(1,8):

print("\nEntering tunnel " + str(i))

response = input("Enter Yes if diamonds are in this tunnel and No otherwise ")
response = response.lower()
if response == 'yes':

print('Diamonds found after searching ' + str(i) + ' mines')

print('Search stops here')

break
๐Ÿงช Try the code out~!

๐Ÿ‘€ Random Search

Computational Thinkingโ€‹

๐Ÿ‘€ Computational Thinking