Go loop - break and continue

Intro break will break out of a loop. It’s a way to stop looping. continue will move on to the next iteration. Let’s see it in action. Examples Example - break package main import "fmt" func main() { pow := make([]int, 10) for i := range pow { pow[i] = 1 << uint(i) if pow[i] >= 16 { break } } fmt.Println(pow) // [1 2 4 8 16 0 0 0 0 0] } Example - continue package main import "fmt" func main() { pow := make([]int, 10) for i := range pow { if i%2 == 0 { continue } pow[i] = 1 << uint(i) } fmt. [Read More]

Go - for loop

Go has only one looping construct, the for loop. The basic for loop looks as it does in C or Java, except that the ( ) are gone (they are not even optional) and the { } are required. As in C or Java, you can leave the pre and post statements empty. for init; condition; post { } Examples Example - Go loop for j := 7; j <= 9; j++ { fmt. [Read More]
loop  for