while-else if

while-else

1、break立即打断循环并且不再执行else

count = 0
while count <= 5:
    count += 1
    if count == 3:
        break
    print("loop",count)
else:
    print("循环执行完了")
print("end")

 

2、while循环后会执行else

count = 0
while count <= 5:
    count += 1
    if count == 3:
        pass
    print("loop",count)
else:
    print("循环执行完了")
print("end")

 

 if

 1 i = 10
 2 if i==10:
 3     print("11")
 4 if i>5:
 5     print("22")
 6 
 7 i = 10
 8 if i==10:
 9     print("11")
10 elif i>5:
11     print("22")

 

都是if的话两个分支都会走

elif满足第一个条件就不会走elif

posted @ 2018-12-16 22:56  ccqc  阅读(178)  评论(0编辑  收藏  举报