Read in value with while loop - C Statement

C examples for Statement:while

Description

Read in value with while loop

Demo Code

#include <stdio.h>
int main(void)
{
    const int secret_code = 13;
    int code_entered;
    //w w w.  j a  va 2 s. c  om
    printf("Guess a number: ");
    scanf("%d", &code_entered);
    while (code_entered != secret_code)
    {
        printf("secret code number: ");
        scanf("%d", &code_entered);
    }
    printf("Congratulations!\n");
    return 0;
}

Result

Here is the general form of the do while loop:

do 
   statement  
while (  expression  );

Related Tutorials