#Concept #Study #CPP
implemented in C++11
loop through a collection of elements without knowing the range of the elements.
```cpp
for (var_type var_name: sequence)
```
`var_type` can also be defined as `auto`, which will choose the variable type based on the data that is inside the variable.
### Example with array
```cpp
int scores [] {100, 90, 97};
for (int score : scores)
cout << score << endl;
// Console Output:
/*
100
90
97
*/
```
### Example with Vector
```cpp
vector<double> temps {87.2, 77.1, 80.0, 72.5};
double average_temp {};
double running_sum {};
for (auto temp: temps)
running_sum += temp;
average_temp = running_sum / temps.size();
```
## 🔗Resources