Test your understanding of for, while, break, and nested loops.
int sum = 0; for (int i = 1; i <= 5; i++) { sum += i; } printf("sum = %d\n", sum);
int x = 10; while (x > 0) { x -= 3; } printf("x = %d\n", x);
x > 0 is false and the loop ends. Since x -= 3 subtracts 3 each time, the loop can overshoot 0.
for (int i = 0; i < 10; i++) { if (i == 3) break; printf("%d ", i); }
break exits the loop immediately. The break happens before printf, so 3 is never printed.int count = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { count++; } } printf("count = %d\n", count);