A range-based for loop walks through the elements of a container without explicit iterators or indices. Introduced in C++11, it reduces boilerplate and makes operations on vectors and other containers easier to read. section 1.4.3 section 2.4
Displaying a vector
Use a range-based loop while filling, displaying, querying, or manipulating a vector of numbers. In the Pascal’s triangle exercise, the loop provides a straightforward way to write stored values to the screen before exploring algorithms, ranges, views, and lambdas. section 2.0 section 1.4.3
The feature connects practical container work with newer C++ library facilities:
- Pair it with auto to avoid spelling out element types when walking through a container. section 2.0 section 2.4
- Use it as an accessible step toward full ranges, which provide views, filters, algorithms, and less direct iterator use. section 1.4.3 section 2.4

