0
0
Goprogramming~10 mins

Labelled break and continue in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to break out of the outer loop using a label.

Go
OuterLoop:
for i := 0; i < 3; i++ {
    for j := 0; j < 3; j++ {
        if i == 1 && j == 1 {
            [1] OuterLoop
        }
        println(i, j)
    }
}
Drag options to blanks, or click blank then click option'
Acontinue
Bgoto
Cbreak
Dexit
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'continue' instead of 'break' to exit the loop.
Forgetting to add the label after 'break'.
2fill in blank
medium

Complete the code to continue the outer loop when a condition is met.

Go
Outer:
for i := 0; i < 3; i++ {
    for j := 0; j < 3; j++ {
        if i == 1 && j == 1 {
            [1] Outer
        }
        println(i, j)
    }
}
Drag options to blanks, or click blank then click option'
Askip
Bbreak
Cgoto
Dcontinue
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'break' instead of 'continue' to skip iterations.
Not specifying the label after 'continue'.
3fill in blank
hard

Fix the error by choosing the correct keyword to break the labeled loop.

Go
Loop1:
for x := 0; x < 5; x++ {
    for y := 0; y < 5; y++ {
        if x*y > 6 {
            [1] Loop1
        }
        println(x, y)
    }
}
Drag options to blanks, or click blank then click option'
Abreak
Bcontinue
Cexit
Dgoto
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'continue' to exit the loop causes wrong behavior.
Using 'goto' without proper label placement causes errors.
4fill in blank
hard

Fill both blanks to continue the outer loop and break the inner loop correctly.

Go
OuterLoop:
for i := 0; i < 3; i++ {
    InnerLoop:
    for j := 0; j < 3; j++ {
        if j == 1 {
            [1] OuterLoop
            [2] InnerLoop
        }
        println(i, j)
    }
}
Drag options to blanks, or click blank then click option'
Acontinue
Bbreak
Cgoto
Dskip
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'break' for both blanks causes incorrect loop behavior.
Using 'continue' for both blanks does not exit the inner loop.
5fill in blank
hard

Fill all three blanks to break the outer loop, continue the inner loop, and break the labeled loop correctly.

Go
Label1:
for a := 0; a < 3; a++ {
    Label2:
    for b := 0; b < 3; b++ {
        if a == 1 && b == 1 {
            [1] Label1
        }
        if b == 0 {
            [2] Label2
        }
        if a == 2 {
            [3] Label1
        }
        println(a, b)
    }
}
Drag options to blanks, or click blank then click option'
Acontinue
Bbreak
Cgoto
Dexit
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'goto' or 'exit' which are invalid in this context.
Mixing up which label to use with break or continue.