<jupyter_start><jupyter_text>【python 入門】繰り返し処理 while文の使い方をマスターする!- whileの使い方- while elseの使い方- breakの使い方- continueの使い方- listを取得しながら繰り返す- 無限ループに注意  whileの使い方 処理を5回繰り返す<jupyter_code>count = 0
while count < 5:
    print(count)
    count = count + 1<jupyter_output>0
1
2
3
4<jupyter_text>while elseの使い方 繰り返し処理が完了した後の処理を追加する<jupyter_code>count = 0
while count < 5:
    print(count)
    count = count + 1
else:
    print('countが5になりました。')<jupyter_output>0
1
2
3
4
countが5になりました。<jupyter_text>breakの使い方<jupyter_code>count = 0
while count < 5:
    if count == 3:
        break
    print(count)
    count = count + 1<jupyter_output>0
1
2<jupyter_text>elseを入れてみる<jupyter_code>count = 0
while count < 5:
    if count == 3:
        break
    print(count)
    count = count + 1
else:
    print('繰り返し完了')<jupyter_output>0
1
2<jupyter_text>continueの使い方<jupyter_code>count = 0
while count < 5:
    if count == 3:
        print('count==3の時の処理')
        count = count + 1
        continue
    
    print(count)
    count = count + 1<jupyter_output>0
1
2
count==3の時の処理
4<jupyter_text>このコードでも処理は同じ<jupyter_code>count = 0
while count < 5:
    if count == 3:
        print('count==3の時の処理')
    else:
        print(count)
    count = count + 1<jupyter_output>0
1
2
count==3の時の処理
4<jupyter_text>listを取得しながら繰り返す<jupyter_code>list_a = ['りんご', 'みかん', 'ぶどう']
while list_a:
    print(list_a.pop())<jupyter_output>ぶどう
みかん
りんご<jupyter_text>無限ループに注意<jupyter_code>import time
count = 0
while True:
    print(f'\r{count}', end='')
    count += 1
    time.sleep(1)<jupyter_output>5
StarcoderdataJupyterStructuredCleanDedup