Pythonを勉強していると、かなり早い段階で出てくるのが for と while です。 どちらも「繰り返し処理」に使います。 でも、初学者の方がよく迷うのがここです。 「同じ繰り返しなら、どっちを使えばいいの?」 結論からいうと、使い分けはかなりシンプルです ...
while文の中にif-else文などを組み合わせることもできます。 while文は変数iが10未満の場合作動します。 そしてその変数iの値が2で割り切れる場合はその値を出力、そうでなければ割り切れずという文字列を出力します。
Coding is (of course) about building things to help others. However, creating programs and software has more to do with automating repetitive or complex tasks than anything else. Python’s while loop ...