Bird
0
0

Identify the error in this Kotlin code snippet:

medium📝 Debug Q14 of 15
Kotlin - Loops and Ranges
Identify the error in this Kotlin code snippet:
outer@ for (i in 1..2) {
    for (j in 1..2) {
        if (i == 1) continue outer
        println("i=$i, j=$j")
    }
}
Acontinue@outer should be used instead of continue outer.
Bcontinue cannot be used with a label on an inner loop.
CLabel 'outer' is not defined.
DNo error; code runs correctly.
Step-by-Step Solution
Solution:
  1. Step 1: Check labeled continue syntax

    Kotlin requires the @ symbol when using labels with break or continue, so it must be continue@outer.
  2. Step 2: Verify label definition and usage

    The label 'outer' is correctly defined, so Label 'outer' is not defined. is wrong. Using continue with label without @ causes syntax error.
  3. Final Answer:

    continue@outer should be used instead of continue outer. -> Option A
  4. Quick Check:

    Use continue@label syntax to avoid errors [OK]
Quick Trick: Always use @ with label in continue or break [OK]
Common Mistakes:
MISTAKES
  • Omitting @ symbol in labeled continue
  • Thinking label must be on inner loop
  • Assuming no error when syntax is wrong

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes