For each loop iterates through each member of a list - C++ Statement

C++ examples for Statement:for

Description

For each loop iterates through each member of a list

Demo Code

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
    cout << "The primes less than 20 are:" << endl;
    for(int n : {1, 2, 3, 5, 7, 11, 13, 17, 19})
    {//www . ja  v  a2  s .  c  o  m
        cout << n << ", ";
    }
    cout << endl;

    return 0;
}

Result


Related Tutorials