C examples for Statement:while
Read in value with while loop
#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; }
Here is the general form of the do while loop:
do statement while ( expression );