For loop
for I in Range (): #注意冒号 The default from 0 or from the specified number to the previous number of the given number, the increment is decremented.
For loop provides automatic initialization of variables
forIinchRange (10): Print(I,end =' ')Print() forIinchRange (5,10): Print(I,end =' ')Print() forIinchRange (10,0,-1): Print(I, end =' ')Print()
>>> ================================ RESTART ================================>>>
While loop:
Need to initialize itself, can contain an ELSE statement block
i = 0 while I <: print" )= i + 1print ()
When the number of cycles in advance is indeterminate, the For loop cannot be used such as:
# donesum.pytotal == input ('input a number or "do":')while 'done': = total+ int (s) = input (' input a number or "done": ' )print(' + str (total))
Break #跳出循环
continue #进入下一次循环 less use better
Multilayer loops:
#timestable.py forRowinchRange (1,10): forColinchRange (1,10): Prod= row *ColifProd < 10: Print(' ', end ="') Print(Row * col," ", end ="') Print()
>>> ================================ RESTART ================================>>> 1 2 3 4 5 6 7 8 9 2 4 6 8 ten 18 3 6 9 ( 4 8) 20 5, 6, and ten. 7 off in a-si From 8 to 9 in all. 72.
"Python" Getting Started (iii)