Member-only story
Do While Loop in C with example
2 min readJul 25, 2022
A do-while loop in C is also used to execute and repeat a block of statements depending on a certain condition. It has the following form
do
{
<statement Block>
}
while(<condition>);
where the <condition> is the relational or logical expression that will have the value true or false.
- When the above statement is executed, the computer will execute the statement block without checking the value of the condition.
- After the statement block completes its execution once, the condition is evaluated.
- If the value of the condition is true, the statement block is executed again and is repeated until the condition is false.
Note that the statement block is executed at least once for any value true or false of the condition.
Also read, While Loop in C with Example
Let us take an example below
Print natural numbers from 1 to n using the do while loop in C language
Complete Code:-
#include <stdio.h>
main()
{
int i, n;
printf("Enter the value to n:");
scanf("%d",&n);
//do while loop to print the…