Combining Loops + Conditions

STEP 4 β€” Combining Loops + Conditions (a.k.a. Your Game’s Logic Engine Goes Super Saiyan)

FINAL BOSS TIME. STEP 4 IS HERE, and this is where loops stop being simple gym bros and become full-blown coding ninjas.

We’re combining EVERYTHING: loops, conditions, break, continue, nested loops β€” the whole buffet.

Let’s go wild.

Alright coder, this is it.

The moment your loops stop doing cute little repetitions and start running entire game systems like they’re managing a Fortune 500 company.

In Step 4, we mix:

  • loops
  • nested loops
  • conditions
  • break
  • continue

And we create actual gameplay logic.


1. Example: Enemy Scan System

Your game scans a list of enemies and reacts differently depending on what it finds.

enemies = ["slime", "goblin", "dragon", "orc"]

for e in enemies:
    if e == "dragon":
        print("Boss detected! Retreat!")
        break
    elif e == "goblin":
        print("A goblin appears!")
    else:
        print("Enemy spotted:", e)

Your loop now behaves like a paranoid adventurer with trust issues.

Perfect.

Click Run

2. Example: Inventory Filter

Skip useless items, process the good ones.

inventory = ["rock", "potion", "stick", "elixir"]

for item in inventory:
    if item == "rock":
        continue
    print("Using:", item)

Your loop now refuses to deal with rocks.

Honestly? Same.

Click Run

3. Example: Map Exploration (Nested Loop + Conditions)

map_grid = [
    ["grass", "tree", "grass"],
    ["water", "grass", "rock"]
]

for row in map_grid:
    for tile in row:
        if tile == "tree":
            print("You bump into a tree.")
        elif tile == "water":
            print("You can't swim!")
        else:
            print("You walk across", tile)

Your loop now explores a map like a tiny RPG hero.

Minus the sword.

And courage.

Click Run

Practice (Your Turn!)

Mini-Challenge

Loop through a 2D list of numbers.

  • If a number is 0, skip it.
  • If a number is 9, stop everything.
  • Otherwise print it.
Modify and Run

Your loop now handles danger like a seasoned explorer.

Respect.

You now command:

  • loops
  • nested loops
  • break
  • continue
  • conditions inside loops
  • loops inside conditions
  • full game logic systems

Your code is officially looppowered and unstoppable.