1
count = 0
while count < 5:
print(count)
count += 1
else:
print('終了')
1の実行結果
0
1
2
3
4
終了
2
count = 0
while count < 5:
if count == 2:
break
print(count)
count += 1
else:
print('終了')
2の実行結果
0
1
breakはwhile文全体から抜ける。
なので、
whileと組み合わされたelse以下は
breakで抜けなければ実行される。