...

/

Untitled Masterpiece

This lesson discusses another variation for running loops in Go, i.e., the for range construct

Infinite loop

The condition can be absent like in:

for i:=0; ; i++ or for { }

This is the same as for ;; { } but the ; ; is removed by gofmt. These are infinite loops. The latter could also be written as:

for true { }

But the normal format is:

for { }

If a condition check is missing in a for-header, the condition for looping is and remains always true. Therefore, in the loop-body, something has to happen in order for the loop to be exited after a number of iterations. Always check that the exit-condition will evaluate to true at a certain moment in order to avoid an ...