天天看點

循環退出、流程控制-while

for循環:針對清單,檔案循環

while循環:針對條件循環

1、當n=5時就跳出循環

n=0

while True:

if n==5:

break

print 'this is %d' %n

n+=1

2、當x=q就跳出循環

當x為空,就break

x='quit',就跳過這次循環,繼續下一次循環

while x!='q':

x = raw_input('Please input someting,q for quit: ')

if not x:

elif x=='quit':

continue

print 'continue'

else:

print x

print 'python'

4、隻有while 後面不是0或者空,表達式都為真

循環退出、流程控制-while

本文轉自 jiekegz  51CTO部落格,原文連結:http://blog.51cto.com/jacksoner/2055186