Bird
0
0

Given nested loops labeled outer and inner, which code snippet correctly breaks out of both loops when a condition is met?

hard📝 Application Q9 of 15
Kotlin - Loops and Ranges
Given nested loops labeled outer and inner, which code snippet correctly breaks out of both loops when a condition is met?
Abreak@outer inside inner loop
Bbreak@inner inside outer loop
Ccontinue@outer inside outer loop
Dcontinue@inner inside inner loop
Step-by-Step Solution
Solution:
  1. Step 1: Understand breaking out of both loops

    To exit both loops from inner loop, break must target outer loop label.
  2. Step 2: Identify correct labeled break usage

    break@outer inside inner loop exits outer loop and inner loop immediately.
  3. Final Answer:

    break@outer inside inner loop -> Option A
  4. Quick Check:

    break@outer exits both loops [OK]
Quick Trick: Use break@outer to exit nested loops from inner loop [OK]
Common Mistakes:
MISTAKES
  • Using break@inner only exits inner loop
  • Using continue instead of break to exit loops
  • Placing break@outer outside inner loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes