Repeat
While Loop
Python
count = 5
while count > 0:
count = count - 1
print(count)
The code inside the while
block runs as long as the condition count > 0
evaluates to True.
This will print 4 3 2 1 0 on Console.
count = 5
while count > 0:
count = count - 1
print(count)
else:
print('done')
The else
block in While loop runs when the condition evaluates to False.
The else
block won't be run if:
break
statement executedreturn
statement executed- the exception happens inside the block
This will print 4 3 2 1 0 done on Console.