Complete the code to break out of the outer loop using a label.
outer@ for (i in 1..3) { for (j in 1..3) { if (i == 2 && j == 2) { [1]@outer } println("i = $i, j = $j") } }
Using break@outer exits the outer loop immediately.
Complete the code to continue the outer loop when a condition is met.
outer@ for (i in 1..3) { for (j in 1..3) { if (i == 1 && j == 2) { [1]@outer } println("i = $i, j = $j") } }
Using continue@outer skips the current iteration of the outer loop.
Fix the error in the code to correctly use a labeled continue.
loop@ for (x in 1..3) { for (y in 1..3) { if (x == 2 && y == 1) { [1]@loop } println("x = $x, y = $y") } }
The correct keyword to skip to the next iteration of the labeled loop is continue.
Fill both blanks to create a labeled break and continue in nested loops.
outer@ for (a in 1..3) { inner@ for (b in 1..3) { if (a == 2 && b == 2) { [1]@outer } if (a == 1 && b == 3) { [2]@inner } println("a = $a, b = $b") } }
break@outer exits the outer loop, and continue@inner skips to the next iteration of the inner loop.
Fill all three blanks to use labeled break and continue correctly in nested loops with conditions.
loop1@ for (i in 1..3) { loop2@ for (j in 1..3) { if (i == 3 && j == 1) { [1]@loop1 } if (i == 2 && j == 3) { [2]@loop2 } println("i = $i, j = $j") if (i == 1 && j == 2) { [3]@loop2 } } }
break@loop1 exits the outer loop, and continue@loop2 skips iterations of the inner loop.