Python while循环
1.简单的while循环
【实例】:
number = 1
while number <= 5:
print(number)
number+=1
【运行结果】:
1
2
3
4
5
2.使用break退出循环
【实例】:
number = 1
while number <= 10:
if number == 6:
break
print(number)
number+=1
【运行结果】:
1
2
3
4
5
3.continue语句
执行continue语句,使python忽略continue后面的代码,并返回循环开头,继续执行循环。
【实例】:
number = 0
while number <= 5:
number+=1
if number == 3:
continue
print(number)
【运行结果】:
1
2
4
5
6
o(* ̄▽ ̄*)ブ 感谢观看,希望对你有帮助!