Hello Aash
Here is one way to visualize what goes on as the for loops increase in number
1 For Loop
Code:
for(int a = 0 ; a <= 1 ; a++) //from 0 to 1
cout << a << endl; //output current value of a with new line
This would give
0
1
2 For Loops
Code:
for(int a = 0 ; a <= 1 ; a++) //from 0 to 1
for(int b = 0 ; b <= 1 ; b++) //from 0 to 1
cout << a << b << endl; //output a,b and end line
This would give
00
01
10
11
3 For Loops
Code:
for(int a = 0 ; a <= 1 ; a++) //from 0 to 1
for(int b = 0 ; b <= 1 ; b++) //from 0 to 1
for(int c = 0 ; c <= 1 ; c++) //from 0 to 1
cout << a << b << c << endl; //output a,b,c and end line
This would give
000
001
010
011
100
101
110
111
As you can see, a becomes longer and longer since it has to accommodate the For Loops within its own loop.
The range of a column (top-down) is independent from another.
You can see this by doing
3 For Loops
Code:
for(int a = 0 ; a <= 1 ; a++) //from 0 to 1
for(int b = 0 ; b <= 2 ; b++) //from 0 to 2
for(int c = 0 ; c <= 1 ; c++) //from 0 to 1
cout << a << b << c << endl; //output a,b,c and end line
a b c
0 0 0
0 0 1
0 1 0
0 1 1
0 2 0
0 2 1
1 0 0
1 0 1
1 1 0
1 1 1
1 2 0
1 2 1
b's range is from 0 to 2, in this case.
Good luck