Theory
The single for — three shapes
Other languages have while, do-while, for, foreach… Go has one loop: for. Its three shapes:
Classic — a counter from–to:
for i := 1; i <= 3; i++ {
fmt.Println("Round:", i)
}
"While"-style — just a condition:
attempts := 0
for attempts < 5 {
attempts++
}
Forever + break — spins until something inside stops it:
for {
fmt.Println("Asking again...")
if done {
break // or return — leaves the whole function
}
}
The third shape looks the most dangerous, but it is exactly the backbone of a menu loop: the program must spin for as long as the user wants, and only the user knows how many rounds that is. We use it in the very next step.