Question: I kind of don't get the nested loops, can someone explain to me why the following code is executed 45 times please? Shouldn't the i++ and j++ increment by 1? So first loop should be (0 \* 0), (1 \* 1), (2 \* 2) and so on.

```
for(int i = 0; i < 10; i++)
    for(int j = 0; j < i; j++)
        System.out.println(i * j);

```

Answer: 
outer loop runs `i` times according to value of `i` 

1st i value is `0` last `i` value is `9` because `i<10`.

so inner loop loops `9*10/2` which is `45`

loop time=`0+1+2+.....+8+9` = `9*10/2` = `45`

note . i used this equation to calculate sum of the loop times

```
   1 + 2 + 3 + ... + N = N(N+1)/2

```
Rather than printing out the expression `i * j`, print out the values of `i` and `j` so you can trace through and see whats happening in the loops. The product of `i * j` is really meaningless to understand how many times it loops.

```
for(int i = 0; i < 10; i++)
    for(int j = 0; j < i; j++)
        System.out.println("i " + i + "j " + j ); 

```