Python 入門 ノート (30)while else文

while else 文

while

count = 0
while count < 5:
    print(count)
    count += 1

0
1
2
3
4

while else

count = 0
while count < 5:
    print(count)
        count += 1
else:
    print('done')

0
1
2
3
4
done

while else break

count = 0
while count < 5:
    if count == 1:
        break
    print(count)
    count += 1
else:
    print('done')

0

 

コメント