mickery
0
Q:

else for loop python

for i in range(1, 4): 
    print(i) 
else:  # Executed because no break in for 
    print("No Break") 
5
for x in range(6):
 	print(x, end=' ')
else:
 	print("Break_not_used") 
# 0 1 2 3 4 5 Break_not_used

for x in range(6):
 	print(x, end=' ')
    if x == 5:
      break
else:
 	print("Break_not_used") 
# 0 1 2 3 4 5
3
list = [99, 98, 97, 96, 95, 94]

for number in list:
  if number == 2:
    print("There is a 2 in the list")
  	break
else:
  print("There are no 2's in the list")
  
# The else statement is only reached if the for loop
# has run all the way through without breaking
4

New to Communities?

Join the community