CodeNest

Conditions and loops

Conditions and loops look like this in C (braces mark the block, indentation is just style):

if (x > 10) {
    printf("big\n");
} else {
    printf("small\n");
}

for (int i = 0; i < 5; i++) {
    printf("%d\n", i);
}

while (n > 0) {
    n--;
}

Try it

Print the even numbers from 2 to 10 on a single line, separated by spaces:

2 4 6 8 10
C unavailable
Next
Running C needs a server execution engine, which isn't configured on this deployment. You can still read the lesson and try the code locally.
Loading editor…

Press Ctrl/ + Enter or click Run to see the output here.