For loop: a [11,22, 33,44] foriina: print (I) result: 11223344while loop: i0whilei & amp; lt; 3: # I & amp; lt; 3 is the cyclic condition, if the condition is true, execute the following loop body. if the condition is false, print (I) I + 1 is not executed. Result: 012break and Con... for loop:
A = [11,22, 33,44]
For I in:
Print (I)
Result:
11
22
33
44
While loop:
I = 0
While I <3: # I <3 is a loop condition. when the condition is true, the loop body after execution is not executed. if the condition is false
Print (I)
I + = 1
Result:
0
1
2
Break and Continue:
I = 0
While I <10:
Print ("I->:", I)
If I = 5:
Break # exit all loops when I = 5
I + = 1
Result:
I->: 0
I->: 1
I->: 2
I->: 3
I->: 4
I->: 5
X = 0
While x <9:
For x in range (0, 10 ):
If x = 6:
Continue # when x = 6, jump out of the current loop and continue the next loop
Print ("x->:", x)
Result:
X->: 0
X->: 1
X->: 2
X->: 3
X->: 4
X->: 5
X->: 7 # missing x->: 6
X->: 8
X->: 9
Others:
Enumrate:
A = ["aa", "bb", "cc", "dd"]
For I in enumerate (a, 5): # the default number starts from 0 and can be changed manually.
Print (I)
Result:
(5, 'A ')
(6, 'BB ')
(7, 'CC ')
(8, 'DD ')
Range:
1,
For n in range (1, 10 ):
Print (n)
Result:
1
2
3
4
5
6
7
8
9
2,
For x in range (0, 20, 4 ):
Print (x)
Result:
0
4
8
12
16
# Print in sequence with 4 as the step