Nested Loops
Loops inside loops build tables and patterns. The inner loop completes for each round of the outer loop.
Example
for (int r = 1; r <= 3; r++) {
for (int c = 1; c <= r; c++) printf("*");
printf("\n");
}
for (int i = 1; i <= 3; i++) printf("%d x 3 = %d\n", i, i * 3);Result
* ** *** 1 x 3 = 3 2 x 3 = 6 3 x 3 = 9
Exercise
Print a star.
printf("");
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.