This pattern is licensed under the CC0 Public Domain Dedication.
Iterate over a range of elements without using iterators or indices.
for loop provides a
simple syntax for iterating over elements of a range without using
iterators or indices. It supports arrays, types that provide
end member functions, and types for which
end functions are found via argument-dependent
Lines 6–8 demonstrate iterating over an array,
arr. In each iteration,
value will have the value of each successive element of
Lines 11–13 similarly demonstrate iterating over a
vec (any standard
container will also work). In this case, we have defined
ref as a
reference type, which will allow us to modify the objects stored
09 December 2017