NESTED LOOPS IN C++
NESTED LOOP:
Loop inside another loop is called nested loop
HOW NESTED LOOP IS EXECUTED:
- For each iteration of outer loop the iterations of inner loops are completed
- When inner loop is terminated outer loop is incremented or decremented and the condition is tested again
- There is no condition of loop used in the inner loop or outer loop while do while or for can be used inside each other
Examples:
#include<iostream>
Using namespace std;
Void main()
{
for (int i = 1; i <= 6; i++)
{
for (int j = 1; j <= i; j++)
{
cout<<"*";
}
Cout<<”\n”;
}
}
Output:
*
**
***
****
*****
******
No comments:
Post a Comment