Andrew's Digital Garden

Loops in Go

Go only has one type of loop, the for loop. It contains a initialisation expression, a condition, and a post operation

It reads like most other for loops, but the init and post statements are optional. This lets it function as a while loop.

Regular: for i := 0; i < 10; i++ { While: for i < 10 {

The range keyword can be used to loop over an array or similar lists. The element returned is a copy.

for index, element := range s

[[go]]

Referred in

Loops in Go