break - an example



package main
import (
    "fmt"
    "time"
)
func main() {
    s := 0
    for {
        if s >= 5 { break }
        fmt.Println("s is:", s)
        s++
        time.Sleep(1000 * time.Millisecond)
    }
    fmt.Println("Break happened")
}

...and you get:
s is: 0
s is: 1
s is: 2
s is: 3
s is: 4
Break happened

No comments:

Post a Comment