While loop

suggest change

A while loop executes a block while a condition is true. Use it when the number of iterations is not known in advance. The example reads integers until the user enters 0. Entering 0 makes the condition false, so execution leaves the loop and continues with any subsequent code. If scanf does not convert an integer, the loop stops; otherwise a failed conversion would leave num unchanged and the loop would never end.

#include <stdio.h>

int num = 1;

while (num != 0)
{
    if (scanf("%d", &num) != 1) {
        break;
    }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents