Computer >> Computer tutorials >  >> Programming >> Python

How to use else statement with Loops in Python?


The else block is executed after iterations and before program control exits loop block

x=0
while x<5:
   x=x+1
   print (x)
else:
   print ("else block of loop")
print ("loop is over")