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