/* * File: while_loop.c * Author: D. Sheets * Description: Example of using while loop */ #include int main(void) { char input = '0'; /* The test inside the while loop is tested BEFORE the code inside * the loop will execute. So if we initialized input to 'x' in the * line above, the code inside the while loop will never execute. */ while(input != 'x') { /* The following code will execute once */ char cr; printf("Type x to exit\n"); scanf("%c%c", &input, &cr); /* After the code is executed, the code will return to the beginning * of the while loop and re-check the test condition. As long as the * test condition is true, the code inside the while loop will * continue to execute. */ } /* When we reach this code, input must have been == to 'x' */ return(0); }