1. Home
  2. C Programming
  3. Control Statements
  4. C – do…while Loop

C – do…while Loop

C – do…while Loop

In a programming language, a loop is useful for running iterative tasks. Using a loop a program can execute code block for multiple times as required.

Mainly there are 3 types of loops available in C programming language. Where while loop is one of them. Below is the list if loop available.

  • for loop
  • while loop
  • do-while loop

do while Loop

A do while loop is similar to while loop. It is exit restricted loops. It means the condition is checked at end of the loop. The do while loop must be run for once.

Syntax:

do…while Loop Working

  1. Loop start
  2. Code block is executed.
  3. The conditions are checked. If the condition evaluates to false go to step 4. If the condition evaluates to true then go to step 2.
  4. Exit loop
  5. do while Loop Example

    A sample C programme to calculate the sum of user input integers. The program will exit when the user enters 0.

    Output:

    Enter a number: 5
    Enter a number: 18
    Enter a number: 1
    Enter a number: 0
    Total = 24
    
    Tags , , , ,