C# & .NET Framework Loops — Repeat & Conquer
💡
Exercise 16

For Loop — Building Skyscrapers Floor by Floor 10 XP Easy

Ctrl+Enter Run Ctrl+S Save

Every great city needs towering skyscrapers, and every skyscraper is built one floor at a time. In C#, the for loop is your construction crane — it repeats a block of code a precise number of times.

The for loop has three parts packed into one line — think of it as your construction blueprint:

for (initialization; condition; increment) { // loop body — runs each iteration }
  • Initialization — sets your starting point: int i = 1 ("Start at floor 1")
  • Condition — checked before each iteration: i <= 5 ("Keep going while we haven't finished 5 floors")
  • Increment — runs after each iteration: i++ ("Move up one floor")

Here's a skyscraper going up, floor by floor:

for (int i = 1; i <= 5; i++) { Console.WriteLine($"Floor {i} built!"); } Console.WriteLine($"Skyscraper complete! 5 floors built.");

How the crane moves:

  • Step 1: int i = 1 — crane starts at floor 1
  • Step 2: Is i <= 5? Yes → build floor 1, then i++ makes i = 2
  • Step 3: Is 2 <= 5? Yes → build floor 2, then i++ makes i = 3
  • ...continues until i becomes 6
  • Step final: Is 6 <= 5? No → loop ends, skyscraper complete!

You can also count down using i--. Imagine a demolition countdown:

for (int i = 3; i >= 1; i--) { Console.WriteLine($"Demolition in {i}..."); } Console.WriteLine("BOOM!");

Pro tip: The loop variable i only exists inside the for loop. Try to use it after the closing brace and the compiler will give you an error — the construction crane gets packed up when the job's done! 🏗️

📋 Instructions
**Mission: Build a 5-floor skyscraper!** Your construction crew is ready. Write a program that: 1. Uses a `for` loop to iterate from floor `1` to `5` 2. On each iteration, prints: `Floor X built!` (where X is the floor number) 3. After the loop, prints: `Skyscraper complete! 5 floors built.` Make sure your output matches **exactly** — the city inspector is strict!
Use `for (int i = 1; i <= 5; i++)` to loop from 1 to 5. Inside the loop, use `Console.WriteLine($"Floor {i} built!");`. After the loop ends, print the completion message.
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.