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

infinite loop

  • You don't have to put a condition in the for loop, but that will create an infinite loop.
  • If you happen to run this on the command line, you can press Ctrl-C to stop this program.
  • In this case you will need to use break or some other way to exit the loop.
package main

import (
	"fmt"
)

func main() {
	i := 0
	for {
		fmt.Println(i)
		i++
	}
}
...
285583
285584
285585
285586
285587
285588
^Csignal: interrupt