Go For Loop

Source URL: https://yourbasic.org/golang/for-loop/

Language: go

Created on: 2020-08-19 23:09:42

sum := 0
for i := 1; i < 5; i++ {
    sum += i
}
fmt.Println(sum) // 10 (1+2+3+4)
CODE EXAMPLE The for loop can be used for three-component loops, while loops, infinite loops and for-each range loops. You can exit a loop with break or continue.
content_copy