While loop and break, continue statement, breakcontinue
The basic loop while: while is used to output continuous statements. It simply prints a series of characters (statements) you want ).
For example, print all numbers from 0 to 100:
1 #-*-coding: UTF-8 = *-2 start = 03 while True: 4 5 print (start) 6 if start = 100:7 break8 # start = start + 19 start + = 1
The preceding simple break statement is used in loops to stop all loops.
For example, print all numbers from 0 to 100 and sum them:
1 #-*-coding: UTF-8-*-2 3 sum = 0 4 start = 1 5 while True: 6 print (start) 7 sum = sum + start 8 if start = 100: 9 break10 start + = 111 print sum
Continue is usually used to end the current loop and does not stop all loops.
For example, print 0, 1, 2, 3, 4, 5, 6, 8, 9, 10:
#-*-Coding: UTF-8 = *-start = 0 while True: if start = 7: start + = 1 continue print (start) if start = 10: break # start = start + 1