August 2019
Beginner to intermediate
798 pages
17h 2m
English
The for loop allows you to iterate a predefined number of times, for as long as a condition is valid, or according to a value that is calculated at the beginning of the for loop. Such values include the size of a slice or an array, or the number of keys on a map. This means that the most common way of accessing all the elements of an array, a slice, or a map is the for loop.
The simplest form of a for loop follows. A given variable takes a range of predefined values:
for i := 0; i < 100; i++ {
}
Generally speaking, a for loop has three sections: the first one is called the initialization, the second one is called the condition, and the last one is called the afterthought. All sections are optional.
In the previous loop, the ...
Read now
Unlock full access