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:
int i = 1 ("Start at floor 1")i <= 5 ("Keep going while we haven't finished 5 floors")i++ ("Move up one floor")Here's a skyscraper going up, floor by floor:
How the crane moves:
int i = 1 — crane starts at floor 1i <= 5? Yes → build floor 1, then i++ makes i = 22 <= 5? Yes → build floor 2, then i++ makes i = 3i becomes 66 <= 5? No → loop ends, skyscraper complete!You can also count down using i--. Imagine a demolition countdown:
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! 🏗️