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[])
   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);

About our authors: Team EQA

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

Free Audio Visual Learning kit