C/C++ Arena

Step 6 of 6

Nested loops

A loop inside a loop runs the inner loop completely for every round of the outer one. That's how you walk a grid.

for (int row = 0; row < 2; row++) {
    for (int col = 0; col < 3; col++) {
        printf("*");
    }
    printf("\n");
}

prints two rows of three stars.

Your turn: read n and print a right triangle of # with n rows. For n = 4:

#
##
###
####

Previous: do-while