for statement simplifies the code for iterating through an
array. Line 12 can be read as “for each iteration, assign the next element of
item, then execute the loop’s body.” Thus, for each iteration,
item represents one element value (but not a subscript) in
items. In the range-based
for’s header, you declare a so-called range variable to the left of the colon (
:) and specify the name of an array to the right. You can use the range-based
for statement with most of the C++ Standard Library’s prebuilt data structures (commonly called containers). Lines 12–14 are equivalent ...