0
0
Kotlinprogramming~20 mins

Break and continue behavior in Kotlin - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Kotlin Loop Control Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of break in nested loops
What is the output of this Kotlin code snippet?
Kotlin
fun main() {
    for (i in 1..3) {
        for (j in 1..3) {
            if (j == 2) break
            print("$i$j ")
        }
    }
}
A11 21 22 31 32
B11 21 31
C11 12 13 21 22 23 31 32 33
D11 12 21 22 31 32
Attempts:
2 left
💡 Hint
Remember that break exits the nearest enclosing loop.
Predict Output
intermediate
2:00remaining
Effect of continue in a single loop
What will this Kotlin code print?
Kotlin
fun main() {
    for (i in 1..5) {
        if (i % 2 == 0) continue
        print(i)
    }
}
A135
B12345
C246
D1245
Attempts:
2 left
💡 Hint
continue skips the current iteration when the condition is true.
Predict Output
advanced
2:00remaining
Output with labeled break in nested loops
What is the output of this Kotlin code?
Kotlin
fun main() {
    outer@ for (i in 1..3) {
        for (j in 1..2) {
            if (i * j > 2) break@outer
            print("$i$j ")
        }
    }
}
A11 12 21 22
B11 12 13 21 22 23 31 32 33
C11 12 21 22 31
D11 12 21
Attempts:
2 left
💡 Hint
The labeled break exits the outer loop when condition is met.
Predict Output
advanced
2:00remaining
Continue with label in nested loops
What will this Kotlin code print?
Kotlin
fun main() {
    outer@ for (i in 1..3) {
        for (j in 1..3) {
            if (j == 2) continue@outer
            print("$i$j ")
        }
    }
}
A11 21 31
B11 12 21 22 31 32
C11 13 21 23 31 33
D11 13 22 23 32 33
Attempts:
2 left
💡 Hint
continue@outer skips to next iteration of outer loop when j == 2.
🧠 Conceptual
expert
2:00remaining
Behavior of break and continue in Kotlin loops
Which statement about break and continue in Kotlin is correct?
AUsing break or continue without labels always exits all nested loops.
BA break statement can only exit the innermost loop and cannot use labels.
CA continue statement skips the rest of the current iteration and can use labels to skip outer loops.
DLabels in Kotlin can only be used with break, not with continue.
Attempts:
2 left
💡 Hint
Think about how labels affect loop control in Kotlin.