流程控制之 for 循环
流程控制之for循环
for 循环条件语句
for i in range(3):
print(i)
# 0
# 1
# 2
for + break 循环语句
- break 结束 for 循环
lis = [1,2,3,4,5,6]
for i in lis:
if i == 4:
break
print(name)
# 1
# 2
# 3
for + contine 循环语句
- contine 结束本次 for 循环,进入下一次循环
lis = [1,2,3]
for i in lis:
if i == 2:
contine
print(name)
# 1
# 3
for 循环的嵌套
- 外部 for 循环一次,内部 for 循环所有
for i in range(2):
for j in range(2):
print(i,j)
#0 0
#0 1
#1 0
#1 1
千里之行,始于足下。