/* * File: do_while_loop.c * Author: D. Sheets * Description: Example of using do-while loop */ #include int main(void) { char input; /* Note that with a do-while loop, we don't need to worry about * initializing input prior to getting to the loop, since the test * will not occur until after the loop has executed the first time. */ do { /* The following code will execute at least once */ char cr; printf("Type x to exit\n"); scanf("%c%c", &input, &cr); /* After the code is executed, the test below will be checked, if * it is true (it evaluates to non-zero) then the code within the * do-while will be executed again. It will continue to execute * as long as the test evaluates to true. */ } while(input != 'x'); /* When we reach this code, input must have been == to 'x' */ return(0); }