The enhanced style for can only cycle through an array sequentially, from start to finish.It is also known as the for each loop. The enhanced for loop was introduced in c++ as a simpler way to iterate through all the elements of a Collection (Collections are not covered in these pages). It can also be used for arrays, as in the above example, but this is not the original purpose. The for each loops are simple but inflexible. They can be used when you wish to step through the elements of the array in first-to-last order, and you do not need to know the index of the current element.
Syntax:
for( Datatype item : array )
{
// body of loop;
}
The program is written in C++ programming language and it displays the elements of an integer array using a range-based for loop. Here's a step-by-step explanation of the program:
//For Each #include<iostream> using namespace std; int main() { int a[]={65,66,67,68,69,70}; for(auto x : a) { cout<<x<<endl; } return 0; }
65 66 67 68 69 70To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions