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

```
As the other answers already explain the loops I won't do it. But if you make your code output a little more information, you can more easily see what happens.

```
public static void main( final String[] args )    
    {
        int counter = 0;
        for ( int i = 0; i < 10; i++ )
        {
            System.out.println( "outerloop: i = " + i );
            System.out.println( "___________________________" );
            for ( int j = 0; j < i; j++ )
            {
                System.out.println( "innerloop: i = " + i + " & j = " + j );
                System.out.println( "Counter: " + counter + " calculation: " + i + " * " + j + " = " + ( i * j ) );
                counter++;
            }
            System.out.println( "___________________________" );
        }
    }

```

This is how I did it in school to understand what the code is doing.