C++ Snippet
Range-Based For Loop Patterns
Difficulty: Easy
The range-based `for` loop (C++11) is the idiomatic way to iterate any container or any type with `begin()` / `end()`. This snippet covers the three reference flavours (by value, by const reference, by mutable reference), iterating over arrays and `std::initializer_list`, and how to also access the index when you need it. Get the reference forms right and you avoid both copies and accidental mutations.
