Step 2 of 6
for loops
A for loop puts the three parts of a counting loop on one line:
for (int i = 0; i < 5; i++) {
printf("%d ", i);
}
// 0 1 2 3 4
- init
int i = 0runs once - condition
i < 5is checked before each round - update
i++runs after each round
Your turn: read n and print the squares from 1 to n on one line, separated by spaces. For n = 4: 1 4 9 16.