7.5. Range-Based for Statement
As we’ve shown, it’s common to process all the elements of an
array. The new C++11 range-based for statement allows you to do this without using a counter, thus avoiding the possibility of “stepping outside” the
array and eliminating the need for you to implement your own bounds checking.
Error-Prevention Tip 7.2
When processing all elements of an array, if you don’t need access to an array element’s subscript, use the range-based for statement.
The syntax of a range-based
for statement is:
for ( rangeVariableDeclaration ...