C/C++ Arena

Step 1 of 6

while loops

A while loop repeats its block as long as the condition stays true.

int i = 1;
while (i <= 3) {
    printf("%d\n", i);
    i++;
}

This prints 1, 2, 3. Forget the i++ and the loop runs forever. On this site, an infinite loop gets stopped after 3 seconds.

Your turn: read n and count down from n to 1, one number per line, then print GO!.

Next: for loops