0Pricing
Go Academy · Lesson

break, continue and Labels

Loop control flow and labeled breaks

Loop Control Fundamentals

Go provides three keywords for controlling loop execution:

  • break — exits the current loop or switch
  • continue — skips to the next iteration
  • goto — jumps to a labeled statement (rarely used)

Labels extend break and continue to work with outer loops.

break in a Loop

break immediately exits the innermost for, switch, or select statement:

for i := 0; i < 100; i++ {
    if i*i > 50 {
        break
    }
    fmt.Println(i)
}

All lessons in this course

  1. if Statements and Init Expressions
  2. The for Loop: All Patterns
  3. switch Statements in Go
  4. break, continue and Labels
← Back to Go Academy