EX33

 1 i = 0
 2 numbers = []
 3 
 4 while i < 6:
 5     print "At the top i is %d" % i
 6     numbers.append(i)
 7 
 8     i = i + 1
 9     print "Numbers now: ", numbers
10     print "At the bottom i is %d" % i
11     
12     
13 print "The numbers:"
14 
15 for num in numbers:
16     print num

while循环跟if类似,但区别在于重复进行,直到while表达式为False为止。

例如:i < 6,那么的6的时候就变成false,这时候就停止打印

 

posted @ 2017-02-09 22:03  LevenLau  阅读(136)  评论(0编辑  收藏  举报