Back to course

Loops in Go: Only For

Go (Golang) for Cloud-Native Microservices

The Power of For

Go doesn't have while or do-while. It only has for.

1. Traditional Loop:

go for i := 0; i < 10; i++ { ... }

2. While-like Loop:

go for condition { ... }

3. Infinite Loop:

go for { ... } // Useful for microservice worker loops

4. Range Loop:

Used for slices and maps. go for index, value := range mySlice { ... }