Challenge - 5 Problems
Loop Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple for loop
What will be the output of this C# code snippet?
C Sharp (C#)
for (int i = 1; i <= 3; i++) { Console.Write(i + " "); }
Attempts:
2 left
💡 Hint
The loop starts at 1 and runs while i is less than or equal to 3.
✗ Incorrect
The loop starts at 1 and increments by 1 until it reaches 3, printing each number followed by a space.
🧠 Conceptual
intermediate1:30remaining
Why use loops instead of repeated code?
Why are loops useful in programming?
Attempts:
2 left
💡 Hint
Think about writing less code to do the same task multiple times.
✗ Incorrect
Loops let us repeat tasks easily without copying and pasting code, making programs shorter and easier to change.
❓ Predict Output
advanced2:30remaining
Output of nested loops
What will this nested loop print?
C Sharp (C#)
for (int i = 1; i <= 2; i++) { for (int j = 1; j <= 2; j++) { Console.Write(i * j + " "); } }
Attempts:
2 left
💡 Hint
Multiply i and j for each pair in the loops.
✗ Incorrect
The outer loop runs i=1 and i=2. For each i, inner loop runs j=1 and j=2. Multiplying gives 1*1=1, 1*2=2, 2*1=2, 2*2=4.
❓ Predict Output
advanced2:00remaining
Output of while loop with break
What will this code print?
C Sharp (C#)
int count = 0; while (true) { count++; if (count == 3) break; Console.Write(count + " "); }
Attempts:
2 left
💡 Hint
The loop stops before printing when count reaches 3.
✗ Incorrect
The loop increments count, checks if it is 3 to break, else prints count. So it prints 1 and 2, then stops.
🧠 Conceptual
expert3:00remaining
Why loops improve program flexibility
How do loops help programs handle different amounts of data without changing code?
Attempts:
2 left
💡 Hint
Think about how loops use conditions to repeat tasks.
✗ Incorrect
Loops use conditions or counters to repeat code as many times as needed, adapting to data size without rewriting code.