Bird
0
0

Identify the error in this Kotlin code snippet:

medium📝 Debug Q6 of 15
Kotlin - Loops and Ranges
Identify the error in this Kotlin code snippet:
outer for (i in 1..3) {
  for (j in 1..3) {
    if (j == 2) break@outer
    print("$i$j ")
  }
}
Abreak@outer cannot be used inside nested loops
BLabel 'outer' is missing a colon after it
Cprint statement syntax is incorrect
Dfor loop range syntax is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check label declaration syntax

    Labels must end with a colon, e.g., outer: for(...)
  2. Step 2: Identify missing colon error

    The code uses 'outer for' without colon, causing syntax error.
  3. Final Answer:

    Label 'outer' is missing a colon after it -> Option B
  4. Quick Check:

    Label syntax requires colon: label: for(...) [OK]
Quick Trick: Always put colon after label name [OK]
Common Mistakes:
MISTAKES
  • Omitting colon after label
  • Misplacing label inside loop body
  • Assuming break@label invalid in nested loops

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes