A range-for loop in C++

The so-called range-based for loop appeared in the C++ 11 standard, together with the auto keyword gives us a very powerful and idiomatic way of looping over things. Let’s start with a simple array. #include <iostream> int main() {     int odd_data[] = {1, 3, 5, 7, 9};     for (auto x : odd_data)         std::cout << x << “\n”; } Here, the for loop goes over all the elements of the odd_data array, and you … Continue reading “A range-for loop in C++”