0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

①for/ifの考え方を日常生活のイベントに当てはめてみた!

0
Last updated at Posted at 2026-08-24

💡Introduction

日常生活のイベントで、for / if の考え方で行われているものを一例として残します。
もっとプログラミングを自然な形で考えたいと思い、書くことにしました。

🏠 ① 洗濯物を干す(for → if)

洗濯物を1つずつ干す(for)
→ その中で「濡れてるか?」を判定(if)

laundry.py
for cloth in laundry:
    if cloth.is_wet():
        hang(cloth)

日常そのまま。

🍱 ② お弁当のおかずを詰める(for → if)

おかずを順番に詰める(for)
→ 「汁が多いものは入れない」(if)

lunch_box.py
for item in okazu_list:
    if not item.is_soup():
        bento.add(item)

これも自然。

🛒 ③ スーパーで買い物する(for → if)

棚の商品を見ていく(for)
→ 「安いものだけ買う」(if)

shopping.py
for product in shelf:
    if product.price < 200:
        cart.add(product)

完全に日常。

🚶 ④ 歩いている時に “信号が赤なら止まる”(for → if)

歩くステップを繰り返す(for)
→ 赤信号なら止まる(if)

traffic_light.py
for step in walk:
    if signal == "red":
        stop()

これもそのまま。

📱 ⑤ LINE の通知を順番に見る(for → if)

通知を順番に見る(for)
→ 重要なメッセージだけ返信(if)

notification.py
for message in notifications:
    if message.is_important():
        reply(message)

日常の行動そのまま。

🧹 ⑥ 部屋の掃除(for → if)

部屋の場所を順番にチェック(for)
→ 汚れてる場所だけ掃除(if)

cleaning.py
for spot in room:
    if spot.is_dirty():
        clean(spot)

これも自然。

🎮 ⑦ ゲームのターン処理(for → if)

ターンを繰り返す(for)
→ HP が 0 ならゲームオーバー(if)

game.py
for turn in range(100):
    if hp <= 0:
        game_over()
        break

ゲームは for/if の塊。

🧠 まとめ:日常は “for の中に if” だらけ

  • 繰り返す(for
  • 条件を満たしたら何かする(if

この2つの組み合わせは、
人間の行動そのもの。

だからプログラミングの for / if は直感的に理解できる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?