// C++ program to demonstrate use of foreach
#include <iostream>
using namespace std;
int main()
{
int arr[] = { 10, 20, 30, 40 };
// Printing elements of an array using
// foreach loop
for (int x : arr)
cout << x << endl;
}
//output:
//10
//20
//30
//40
int arr[] = { 10, 20, 30, 40 };
for (int x : arr)
{
// Stuff with x
// x will first have 10, then 20 and so on.
}
for(type variable_name : array/vector_name)
{
loop statements
...
}
// REMEMBER TO REPLACE '???'
// with the data structure to iterate on
for(int i=0; i<???; ++i) {}
for(auto it=???.begin(); it!=???.end(); ++it) {}
for(auto &obj : ???) {}