Codeloft
0 0 XP

Loops

7 min 20 XP + 10 for no hints

A for loop repeats code a set number of times: for (int i = 1; i <= 5; i++) starts at 1, runs while i <= 5, and adds 1 each time.

A while loop repeats as long as a condition stays true. Make sure something inside it changes, or it never stops.

i++ adds 1 to i, and i += 2 adds 2, which is handy for counting in steps.

Example (inside Main)
for (int i = 3; i >= 1; i--)
{
    Console.WriteLine(i);
}
Console.WriteLine("Lift off!");
Output
3
2
1
Lift off!
i-- counts down by one, the opposite of i++.

Your tasks

0 of 3 done
  1. Write a for loop that counts from 1 to 10
  2. Print the loop variable with Console.WriteLine
  3. Print the 5 times table with a second loop

Quick check

How many times does for (int i = 0; i < 3; i++) run?

Program.csChecked as you type
No problems found. Unclosed tags, missing semicolons and errors show up here in plain words.