天天看点

循环退出、流程控制-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