- 最終更新
- 2026/08/17
3秒でわかる
同じ処理を条件が続く間くり返す制御構造。for と while が代表で、件数の分からないデータをまとめて処理するときの土台になります。
30秒図解
もう少し詳しく
どういうものか
反復は、for、終了条件だけがwhile です。
for は「リストの全要素にwhile は
なぜ必要か
処理する
もう
具体例
scores = [72, 88, 95, 60, 81]
total = 0
for s in scores: # 対象が決まっているので for
total += s
print(total / len(scores)) # 79.2
# 終了条件だけが決まっている場合は while
n = 1000
digits = 0
while n > 0:
n //= 10
digits += 1
print(digits) # 4int[] scores = {72, 88, 95, 60, 81};
int total = 0;
for (int s : scores) {
total += s;
}
System.out.println((double) total / scores.length); // 79.2つまずきやすいところ
while のrange(1, 5) は似た用語との違い
反復と
覚え方
回数がfor、条件がwhile。この


