Go Lang Notes


Loops

Loops

For loops are the only looping structure in Go Lang but with it you can simulate any While, For While, etc loop.

Basic Syntax: for <int>; <comparision>; <incremntor> { //code block }

Example:

for i := 0; i < 5; i++ {
    // do something
}

for i > 16 {
    i++
}

any of the options for the For loop can be left off also.

Range

the range command can be used with for to easily loop over arrays, lists, etc.