×

go · level 1 · unit 5 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

leaves a loop. skips a round.

break stops a loop straight away, even if it has rounds left. Picture searching your pockets for your keys: once you find them, you stop looking.

continue skips the rest of this round and jumps to the next one. Picture skipping the songs you do not like on a playlist.

Both usually sit inside an if, so they only happen when you want them to.

package main
import "fmt"
func main() {
	for n := 1; n <= 10; n++ {
		if n == 4 {
			break
		}
		fmt.Println(n)
	}
	fmt.Println("Stopped at 4.")
}

break leaves the loop only, and the program carries on with the line after it.