Topic-14: do while loop

Defination:

A do-while loop is a control flow statement in programming languages that is similar to a while loop but with a crucial difference: it evaluates its condition after the code block has been executed, ensuring that the block of code is executed at least once, regardless of the condition’s initial value.

Here’s the basic structure of a do-while loop in most programming languages:

do {

// code to be executed at least once

}

while (condition);

Example-1

// do while loop

//print 1 2 3 4 5 6 7 8 9 10

#include<stdio.h>

int main()

{

int i=1;

do{ printf(“%d\n”,i);

i++;

}

while(i<=10); return 0;

}

OUTPUT:-

1

2

3

4

5

6

7

8

9

10

Leave a Comment

Your email address will not be published. Required fields are marked *