break exits the innermost for, switch, or select. continue jumps to the next iteration of the innermost for. That matches searches like go break loop, golang break for loop, golang continue, continue golang, and continue in golang. For golang break outer loop or golang continue outer loop, add a label. For golang select break, remember a bare break leaves the select, not an outer for—use a label on the for when you need both. Prerequisite: for loops in Go; related concurrency: channels and select.
Tested with Go 1.24 on Linux.
golang break for loop (single loop)
package main
import "fmt"
func main() {
for i := 0; i < 10; i++ {
if i == 4 {
break
}
fmt.Println(i)
}
fmt.Println("done")
}You should print 0 through 3, then done.
Nested loop: inner break only
A break inside the inner for does not stop the outer for:
package main
import "fmt"
func main() {
for i := 1; i < 5; i++ {
for j := 5; j > 0; j-- {
if j == i {
fmt.Printf("outer %d inner %d\n", i, j)
break
}
}
}
}You should see four lines as each outer i pairs with inner j.
golang break outer loop (labeled break)
package main
import "fmt"
func main() {
outer:
for i := 0; i < 5; i++ {
for j := 0; j < 5; j++ {
if i == 2 && j == 2 {
fmt.Println("leaving both loops")
break outer
}
}
}
fmt.Println("after loops")
}You should see leaving both loops then after loops.
golang continue and skipping iterations
package main
import "fmt"
func main() {
for i := 1; i < 10; i++ {
if i%2 != 0 {
continue
}
fmt.Println(i)
}
}You should print even numbers 2 through 8.
golang continue outer loop (labeled continue)
package main
import "fmt"
func main() {
outer:
for i := 0; i < 3; i++ {
for j := 0; j < 3; j++ {
if j == 1 {
fmt.Printf("skip rest of inner when i=%d\n", i)
continue outer
}
fmt.Println("i", i, "j", j)
}
}
}You should see i 0 j 0, a skip line for i=0, then similar for i=1 and i=2.
golang select break: leave the select, not the for
Inside a select, break exits the select. To exit an enclosing for, label the for and break that label:
package main
import "fmt"
func main() {
ch := make(chan int, 1)
loop:
for {
select {
case v := <-ch:
fmt.Println("got", v)
break loop
default:
ch <- 1
}
}
fmt.Println("left for+select")
}You should see got 1 then left for+select.
switch note: break exits switch, not for
Inside a switch nested in a for, a bare break terminates the switch. Use a label on the for if you need to break out of the loop.
Summary
Go break and continue control the innermost for unless you target switch or select. For go break loop vs golang break outer loop, use labels. For golang continue outer loop, use continue Label. For golang select break, pair select with a labeled for when one case should end the whole loop. Prefer small loops and early return from functions when that reads clearer than deep labels.
References
- The Go Programming Language Specification — Break statements
- The Go Programming Language Specification — Continue statements
- For loops in Go
- Go channels

