您的位置:首页 > 编程语言 > Python开发

Python的while语句(continue,break,True)

2017-10-02 21:06 375 查看
while条件循环

>>> i=1
>>> while i<=10:
print(i)
i+=1

1
2
3
4
5
6
7
8
9
10


while 语句”判断条件”还可以是个常值/True,表示循环永远进行下去,需要break跳出循环。

>>>i=1
>>> while True:          ####
print('still OK!')
i+=1
if i>10:
break            ####

still OK!
still OK!
still OK!
still OK!
still OK!
still OK!
still OK!
still OK!
still OK!
still OK!
>>>


Python的continue 语句跳出本次循环,而break跳出整个循环。

continue 语句用来告诉Python 跳过当前循环的剩余语句,然后继续进行下一轮循环。continue语句用在while和for循环中。

>>> for letter in 'Continue':
if letter == 'u':
continue       ####
print('Present letter :', letter)

Present letter : C
Present letter : o
Present letter : n
Present letter : t
Present letter : i
Present letter : n
Present letter : e
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python