·fOR循环
for apple in range(0,20):
print(apple)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
·WHILE循环
a=35
b=70
while a<40 and b<100:
a=a+1
b=b+1
print(a,b)
36 71
37 72
38 73
39 74
40 75
a=35
b=70
while a<40 or b<100:
a=a+1
b=b+1
print(a,b)
36 71
37 72
38 73
39 74
40 75
41 76
42 77
43 78
44 79
45 80
46 81
47 82
48 83
49 84
50 85
51 86
52 87
53 88
54 89
55 90
56 91
57 92
58 93
59 94
60 95
61 96
62 97
63 98
64 99
65 100
·BREAK实现提前退出循环
for i in range(0,30):
print(‘hello %s’%i)
if i>=9:
break
hello 0
hello 1
hello 2
hello 3
hello 4
hello 5
hello 6
hello 7
hello 8
hello 9
for i in range(0,30):
print(‘hello %s’%i)
if i==9:
break
hello 0
hello 1
hello 2
hello 3
hello 4
hello 5
hello 6
hello 7
hello 8
hello 9