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 252. Your C learning is 0.00% complete. Login to check your learning progress.

Further readings

How to write repetitive statements in C? [for, while, do while example, flowchart]
Repetitive tasks in programming. Repetitive statements and loop statements. How to write loop statements. For while do-while loop, syntax and example code.

Write C programming syntax for, while, do while loops.
How to write loop statements in C? How to write a for loop, while loop, do while loop? Study the SYNTAX, FLOW DIAGRAM, with CODE, VIDEO examples.

How to convert for a loop to while loop, vice versa?[GUIDE]
Convert for loop to while loop and vice versa. Understand for, while, do-while loops and write code properly. Also understand on how to convert for, while, do-while to other loops

Write infinite loop statements for 'while', 'do-while' and 'for'?
What is an infinite loop in programming? Need of infinite loop. Write infinite loop statements in C. Example of infinite loop 'for' 'while', 'do-while'.

How to break a loop? How to skip loop iterations with continue? [example and flowchart]
Understanding C continue and break keyword with flowchart and practical example source code. Where to put break or continue in for loop, while loop, do while loop