Challenge - 5 Problems
Break Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of break in nested loops
What is the output of this C# code snippet?
C Sharp (C#)
using System; class Program { static void Main() { for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (j == 2) break; Console.Write(i * 10 + j + " "); } } } }
Attempts:
2 left
💡 Hint
Remember that break exits only the innermost loop.
✗ Incorrect
The break statement stops the inner loop when j == 2, so only j=1 prints for each i. Thus output is 11 21 31.
❓ Predict Output
intermediate1:30remaining
Break inside switch statement
What will this C# program print?
C Sharp (C#)
using System; class Program { static void Main() { int x = 2; switch (x) { case 1: Console.Write("One"); break; case 2: Console.Write("Two"); break; default: Console.Write("Default"); break; } } }
Attempts:
2 left
💡 Hint
The break in switch stops fall-through to other cases.
✗ Incorrect
Since x is 2, the case 2 block runs and prints "Two". The break prevents running other cases.
❓ Predict Output
advanced2:00remaining
Break effect in while loop with continue
What is the output of this C# code?
C Sharp (C#)
using System; class Program { static void Main() { int i = 0; while (i < 5) { i++; if (i == 3) break; if (i == 2) continue; Console.Write(i + " "); } } }
Attempts:
2 left
💡 Hint
Note that continue skips printing when i == 2, and break stops loop at i == 3.
✗ Incorrect
i=1 prints, i=2 triggers continue (skips print), i=3 triggers break (loop ends). So output is "1 ".
🔧 Debug
advanced1:30remaining
Identify error with break outside loop
What error does this C# code produce?
C Sharp (C#)
using System; class Program { static void Main() { int x = 5; if (x > 3) { break; } Console.WriteLine("Done"); } }
Attempts:
2 left
💡 Hint
Break can only be used inside loops or switch statements.
✗ Incorrect
Using break outside a loop or switch causes a compile-time syntax error.
❓ Predict Output
expert2:30remaining
Break with labeled loops simulation
What is the output of this C# code simulating labeled break behavior?
C Sharp (C#)
using System; class Program { static void Main() { bool exitOuter = false; for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (i * j > 3) { exitOuter = true; break; } Console.Write(i * 10 + j + " "); } if (exitOuter) break; } } }
Attempts:
2 left
💡 Hint
The inner break stops inner loop, the flag triggers break of outer loop.
✗ Incorrect
The loops print until i*j > 3. When i=2,j=2 (4>3), inner break and outer break run. Output is 11 12 13 21.