while loop nest
There is also the while loop while loop
while nested format
1 the while Condition 1: 2 when the condition 1 is satisfied, repeating events . 3 . 4 the while Condition 2: . 5 when the two conditions are satisfied, repeating events
Multiplication table
1 i= 1 2 while i<= 9: 3 j = 1 4 while j <= i: 5 print("%d*%d=%-2d" % (j, i, i*j ), end= " ") 6 j += 1 7 print("\n") # 换行 8 i += 1
for loop
The for loop can iterate over any sequence of items, such as list
break 和 continue
The role of break: an immediate end to break the cycle where
Action continue to: continue to satisfy the conditions that skip one cycle, then the next cycle performed
break and continue in a cycle can only be used, can not be used alone,
In the nest cycle, only one cycle of recent work.
for loop format:
for the temporary variables in the need to traverse the object or variables: cyclic code is executed when the condition is satisfied
x = [1,2,3,4,5,6] for i in x: print(i)