Do While Loop in C

Learn all about "do while loop", when and how to use do while loop?

A do-while loop is similar to a while loop. A do-while loop is used when we want to execute the loop at least once.

  • A do-while loop's body executes first and condition checked latter.
  • If the condition is true then the loop body executed again.
  • If the condition is false then the loop stops its execution.
  • A do-while loop is guaranteed to execute at least one time.

Syntax of do while loop

  • You can the condition appears at the end of the loop, so the statements in the loop scope execute once before the condition is tested.
  • If the condition is true then the flow of control jumps back up to do and the statements in the loop execute again.
  • The above process repeats until the condition is false.

Example 1

Output

Problem 1

Can you find the output of the below program:

Example 2

Notice the condition and output of the below program very carefully, you can see the condition is false but still loop scope runs one time.

Output

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

© 2023 GDATAMART.COM (All Rights Reserved)