break, continue and Labels
break leaves, continue skips and labels target outer loops.
Example
package main
import "fmt"
func main() {
outer:
for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
if j == 1 {
continue
}
if i == 2 {
break outer
}
fmt.Println(i, j)
}
}
}Result
0 0 0 2 1 0 1 2
Exercise
Skip a round.
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.