Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

break out from loop

  • break
package main

import (
	"fmt"
)

func main() {
	i := 0
	for {
		fmt.Println(i)
		i++
		if i > 5 {
			break
		}
		fmt.Println("tail")
	}
	fmt.Println("after loop")
}
0
tail
1
tail
2
tail
3
tail
4
tail
5
after loop