While loop checks the input condition first and exits if the condition fails. Do-while loop enters the loop for the first time by default and executes the statements inside the loop before checking the condition. This nature of do-while loop is essential for making a menu driven program where we need to show a list of options to the user and wait for the userís input. The following example shows a menu driven program using do-while loop.

int main(int argc, char *argv[])
{
  do
  {
   printf("Add an user [a]\n");
   printf("Delete an user [d]\n");
   printf("View user's record [v]\n");
   printf("Modify user's record [m]\n");
   printf("Press ESC to exit\n:");
   key = getch();
   
  }while(key != 27);
}

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

execution sequence, loop statements, for, while, do-while loop syntax, for to while, do-while and while usage, infinite loops, break and continue, switch statement, continue in switch and loops,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan