continue :结束当前迭代,并跳到下一次迭代开头
1 i =02 num = [1,2,3,4,5]3 while i < 3:4 print(i)5
6 for j innum:7 print("for循环第%d次"%j)8 if j < 2:9 print("if循环,第%d次"%j)10 elif j == 4:11 break #跳出for循环进入while循环,可见break跳出了两层循环
12 else:13 continue #跳到第6行for循环
14 i += 1
输出:
0
for循环第1次
if循环,第1次
for循环第2次
for循环第3次
for循环第4次
1
for循环第1次
if循环,第1次
for循环第2次
for循环第3次
for循环第4次
2
for循环第1次
if循环,第1次
for循环第2次
for循环第3次
for循环第4次