Reading a Nested for loop.

I'm reviewing for a test and i'm having trouble reading how this outputs, can someone explain to me how its executing using like a chart or something??

like:

i j k
1 0 0
1 1 2 etc.



1
2
3
4
5
6
7
8
9
10
11
12
13
  #include <iostream>
using namespace std;

void main()
{
	int i, j, k = 0;

	for (i = 1; i < 5; i++)
		for (j = 0; j < i; j += 2)
			k += i;
	cout << k << endl;

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>

int main(){
	int i, j, k = 0;
	
	std::cout << "line i j k\n";

	for (i = 1; i < 5; i++){
		std::cout << "9    " << i << ' ' << j << ' ' << k << std::endl;
		for (j = 0; j < i; j += 2){
			std::cout << "11   " << i << ' ' << j << ' ' << k << std::endl;
			k += i;
			std::cout << "13   " << i << ' ' << j << ' ' << k << std::endl;
		}
	}
}
/*
Output:
line i j k 
9    1 1 0 
11   1 0 0 
13   1 0 1 
9    2 2 1 
11   2 0 1 
13   2 0 3 
9    3 2 3 
11   3 0 3 
13   3 0 6 
11   3 2 6 
13   3 2 9 
9    4 4 9 
11   4 0 9 
13   4 0 13
11   4 2 13
13   4 2 17
*/
Topic archived. No new replies allowed.