0

nested loops any one explain me in easy way plz

2nd Mar 2019, 2:19 PM
AFTAB ALI
AFTAB ALI - avatar
2 Antworten
+ 1
thankx boris ❤️
2nd Mar 2019, 4:19 PM
AFTAB ALI
AFTAB ALI - avatar
0
Simply, if you put a loop in another loop, you'll have a nested loop. Example 1: for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { cout << j; } cout << endl; } Output: 01234 01234 01234 As you can see, on each iteration of the outer loop you execute the inner loop. Example 2: for (int i = 0; i < 2; i++) { cout << "i = " << i << endl; for (int j = 0; j < 4; j++) { cout << "j = " << j << endl; cout << "k = "; for (int k = 0; k < 6; k++) { cout << k; } cout << endl; } cout << endl; } Here you'll get 2(i) x 4(j) of 012345(k). You can practice it in the playground.
2nd Mar 2019, 4:05 PM
Boris Batinkov
Boris Batinkov - avatar