for { fmt.Println("loop") break }
for i := 0; i <= 5; i++ { if i % 2 == 0 { continue } fmt.Println(i) }
i := 1 for i <= 3 { fmt.Println(i) i++ }
nums := []int{2, 3, 4} sum := 0 for _, num := range nums { sum += num } fmt.Println("sum:", sum)
for i := 0; i <= 10; i++ { fmt.Println("i: ", i) }
x := 42.0 switch x { case 0: case 1, 2: fmt.Println("Multiple matches") case 42: // Don't "fall through". fmt.Println("reached") case 43: fmt.Println("Unreached") default: fmt.Println("Optional") }
See: Switch
x := "hello go!" if count := len(x); count > 0 { fmt.Println("Yes") }
if _, err := doThing(); err != nil { fmt.Println("Uh oh") }
a := 10 if a > 20 { fmt.Println(">") } else if a < 20 { fmt.Println("<") } else { fmt.Println("=") }