Go Loops (For and While)
Go only has one looping construct: the for loop. There is no while or do-while keyword in Go, but you can achieve the same behavior using for.
1. The Classic For Loop
The most basic type of loop, similar to C or Java.
2. The "While" Style Loop
By omitting the initialization and post statements, for behaves exactly like a while loop.
3. Infinite Loops
A for without any condition will run forever until you break out of it or return from the function.
4. Continue and Break
continue: Skip the rest of the current iteration and start the next one.break: Exit the loop entirely.
5. Loop over Collections (Range)
To iterate over arrays, slices, or maps, use the range keyword.