Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
fun main() {
for (i in 1..6) {
if (i == 2) continue
if (i == 5) break
println(i)
}
}1 3 4
- Expecting
1 3 4 5: thinkingbreaklets the current lap finish. It leaves the loop at once, soprintln(i)never runs for5. - Expecting
1 3 4 6: mixing upbreakandcontinue.continueskips one lap and the loop goes on;breakends the whole loop.
- What does the program print if
breakis replaced withcontinue? - How would you leave both loops at once when one
forsits inside another?