#include <vector>
#include <iostream>
std::vector<int> testingVector{1,2,3,4,5};
/* firstly you define the type in this case it is int then you pass it as
reference with "&" then you choose your "name" for element in this case
it is element after the : you type in name of the vector variable
you use the element as a varibale which will loop around every element in
the vector
*/
for (int& element : testingVector)
{
element++;
}
OUTPUT: 2 3 4 5 6
//equivalent in normal for loop would be this
for(int i{}; i < testingVector.size(); i++)
{
testingVector[i]++;
}
for (variable : collection) {
// body of loop
}