Animate the Inverted Triangle star pattern and see how changing the inner loop bound flips the shape.
About this algorithm
The inverted triangle is a countdown drawn in stars. The top line is the longest, n stars, and every line after it is one star shorter, ending with a lone star in the bottom left corner. The skill it teaches is making an amount go down while the loop counter goes up.
Open this page once the growing triangle makes sense. The left edge stays straight, so you only deal with one changing number, and that number now shrinks: n - i on line i. You will reuse exactly this subtraction for the inverted pyramid and for the lower half of a diamond, which is why it is worth practising on its own first. When the shrinking shape needs to stay centred, the inverted pyramid page adds the leading blanks that do it.
i still runs 0, 1, 2 up to n - 1. Line 0 comes out first, and it is the widest one.
Line 0 wants n stars, line 1 wants n - 1, and so on, so line i wants n - i. Plug in the two ends to be sure: n when i = 0, and 1 when i = n - 1.
Positions 0 through n - i - 1 are filled, so the test is j < n - i, strictly less. A position at or past n - i is blank. Each new line moves that cut-off one place to the left.
Print a newline after the last position and carry on with the next i.
The page loads n = 5. On line 0 the test is j < 5, true for all five positions, so it prints five stars. Line 1 tests j < 4 and prints four, line 2 tests j < 3 and prints three, line 3 tests j < 2 and prints two, and line 4 tests j < 1 and prints one. Adding them gives 5 + 4 + 3 + 2 + 1 = 15 stars and 10 blanks across 25 cells. Those totals equal the growing triangle's, since these are its lines in reverse order.
An equally good version runs the outer loop backwards: for k = n down to 1, print k stars. No subtraction is needed. This page keeps i counting up so you can set it beside the growing triangle, whose test is j <= i, and see that only the condition changed.
Using j <= n - i gives every line below the top one star too many, so the last line ends with two stars instead of one. Check the first and last lines by hand: n stars on top, one at the bottom.
Time: the double loop tests all n × n positions once, and a little over half of them get a star. Space: beyond the output, the loop keeps only i, j and n.