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

C – do while loop

C – do-while Loop Statement

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

  • Step 1 – Loop start
  • Step 2 – Code block is executed.
  • Step 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.
  • Step 4 – Exit loop

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 , , , ,
Was this article helpful to you? Yes 2 No 3
Advertisement