For Each Statement
#include <iostream> int main() { // This form of the for loop goes through a list of items. // Also very useful for arrays, when we get there. for(int i: { 4, 5, 19, 3, 55, 6 }) { std::cout << "[" << i << "] "; } std::cout << std::endl; }

This list form of a for loop has been part of the language starting with the 2011 standard. It is technically called a range-based for loop, but most often referred to as a foreach loop. You will probably recognize it from the similar loop in Java.

Java's foreach loop can run through objects in Java's collections framework. C++ has a similar feature which we'll get to later, and the foreach loop works fine with that. But it also works with plain arrays, and with bracketed lists as shown here.