Python基础Day02

 

 打印1、2、3、4、5、6、8、9、10:

1 count = 0
2 while count < 10:
3     count += 1
4     if count == 7:
5         pass
6     else:
7         print(count)
View Code
count = 0
while count < 10:
    count += 1
    if count == 7:
        continue
    print(count)
View Code
count = 0
while count < 10:
    count += 1
    if count == 7:
        continue
    else:
        print(count)
View Code

 while正常执行完毕才会执行else,如果while被break打断,则不会执行else:

count = 1
while count < 10:
    if count == 6:
        break

    print(count)
    count += 1
else:
    print("----------")
View Code

 

posted @ 2020-03-21 14:24  Peter_Yi  阅读(106)  评论(0)    收藏  举报