久しぶりの初歩の初歩ですが、プログラムを書いていますか? 今日のテーマは、繰り返しループの話です。 ループは基本的な仕組みですが、最もプログラムの恩恵を実感できる重要な仕組みです。人が最も嫌う反復作業もこれでラクラクです。 ループとは ...
Pythonのリストは、複数の値をまとめて格納できる便利なデータ構造です。では、そのリストの中にある全ての要素に対して、一つずつ順番に、何か特定の処理(例えば、画面に表示する、など)を自動で実行したい場合は、どうすればよいのでしょうか?
In Python, there are often multiple ways to achieve the same task, and iterating over data structures like lists is no exception. Two popular methods for iteration are list comprehension and for loops ...
次に、プログラムの流れを制御する制御文を説明しましょう。制御文は大別すると「分岐」と「ループ」に分かれます。 分岐は容易に理解できる機能で、基本は「if文」です。先ほどの「if i % 2 == 0」はif文の例だったのです。if文は次のように使います。
In the early days of C, you’d occasionally see someone — probably a former Pascal programmer — write something like this: #define BEGIN { #define END } This would usually initiate complaints about ...