W7Code » C Language » Do While Loop in C Programming Language

The do while loop in C, works similar to the while loop, but with one big difference:

  • The do while loop:
    • runs at least one de code, independently of the condition we have defined.
  • The while loop:
    • only runs the code if the condition is true.

Do While loop syntax:


Syntax Explained:

  1. First we run the code;
  2. And then we check the condition:
    1. if the condition is true continue doing the loop;
    2. else if is false, stop and go out of do while loop.

The do while loop is normally used to create menus.


Code Explained

This is just a brief explanation of what the code does, all the detailed information is commented in the code example. This program creates a simple menu for users, this menu have 4 options:

  • 1 – Add New User;
  • 2 – Change User;
  • 3 – Delete User;
  • 0 – Exit.

This options are showed to the users. When we work with menus normally, we ask to users input an integer to choose the menu option, only because is more easier and kick to set the conditions and use in the switch statement to. In this switch statement  we define what we are going to do, after the user choose an option.


If you have any doubts, or want more examples of do while loop, please comments bellow!

Leave a Reply