Labels, break and continue
A label names a loop so break and continue can target an outer loop from inside a nested one.
Example
outer:
for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
if j == 2 {
continue outer
}
if i == 2 {
break outer
}
fmt.Print(i, j, " ")
}
}
fmt.Println()Result
0 0 0 1 1 0 1 1
Exercise
Leave an outer loop.
outerQuiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.