do-while loop in C
In C, ado-while
loop is a type of loop construct that executes a block of code repeatedly as long as a specified condition is true. Unlike thewhile
loop, thedo-while
loop guarantees that the code block is executed at least once, even if the condition is initially false. Here's the basic syntax of a do-while
loop in C:
do {
// Code block to be executed
} while (condition);
Here's how it works:
1. The code block enclosed within the do
and while
braces is executed first.
2. After the code block is executed, the condition specified in the while
statement is evaluated.
3. If the condition is true
, the loop iterates, and the code block is executed again. This process continues until the condition becomes false
.
4. If the condition is initially false
, the code block is still executed at least.
In This Example we Print table of 2
Result is here:-