What is the syntax for While loops?

while <expression>:
     <code to be executed>
#executes until expression becomes false
#example
numb=0
while numb<5:
 print(numb, " is a number smaller than five")
 numb = numb + 1

#output
0 is a number smaller than five
1 is a number smaller than five
2 is a number smaller than five
3 is a number smaller than five
4 is a number smaller than five

 

 

Advertisements