1、Python While 循环语句
while 判断条件:
执行语句……
当判断条件为true时,进入循环。
返当判断条件为false时,循环结束。
2、循环使用else 语句、
在Python中,while...else在循环添加为false时 执行else语句。
count = 0 while count < 5:
print count, " is less than 5"
count = count + 1
else:
print count, " is not less than 5"
以上实例输出结果为:
0 is less than 5
1 is less than 5
2 is less than 5
3 is less than 5
4 is less than 5
5 is not less than 5
3、简单语句组(将while循环中只有一句话)
flag=1
while (flag) : print 'Given flag is really true!'
print "Good bye!"
注意:以上的无限循环你可以使用 CTRL+C 来中断循环。