/* File: nobreak2.c Using a flag instead of break statement to control a while loop. */ #include int main() { int done ; char pick, cr ; done = 0 ; // 0 is false while (!done) { printf("\033[2J"); // clear screen printf("\033[H"); // go home printf("You're wish is my command. Pick one:\n\n") ; printf(" A - Take me to Alaska\n") ; printf(" B - Bring me a shrubbery\n") ; printf(" C - I want a million $\n") ; printf(" X - all done\n\n") ; scanf("%c%c", &pick, &cr) ; switch (pick) { case 'A' : printf("Alaska is rather cold this time of year.\n") ; break ; case 'B' : printf("Sorry, fresh out of shrubbery.\n") ; break ; case 'C' : printf("I'll work on that. Anything else?\n") ; break ; case 'X' : printf("Goodbye!\n") ; done = 1 ; break ; default: printf("I don't understand. Please pick a listed command.\n") ; } if (! done) { printf("\nPress 'enter' to continue...") ; scanf("%c", &cr) ; } } return 0 ; }