
programming
golang
go
Go Loops
0 min read (92 words)
There is For loop in Go, pretty easy:)
while True = just for
for {
fmt.Printf("Slice time:\n")
}
For each in = range (similar to enumerate() in Python) is used to go over slices or maps
a := []string{"a1", "b1", "b1", "b1", "b1", "b1"}
for index, value := range a {
fmt.Printf("Index %v: %vn", index, value)
}

Use _ if you don't need to use index or value
a := []string{"a1", "b1", "b1", "b1", "b1", "b1"}
for _, value := range a {
fmt.Printf("Value: %vn", value)
}
IF ELSE is the same


About
Dmitry Golovach
Principal Network Engineer and AI enthusiast. Always learning, always building.