Do-While Loop In C

 

Do-While Loop Definition :

Do-While loop in C is defined as control structure, which allows to execute the block of codes for specific number of times until the condition is false.

For loop is also known as exit-controlled loop.

Syntax:

do  
{ 
//blocks of codes;  
   
}while(condition);

Working of Do-While Loop :

The Do-While loop follows a very organized methodology in which it first initializes a condition, then performs conditional statements and before updating data.

It has 3 parameters : Initialization, condition and updation.

Initialization :

The conditional variable that iterates the value or aids in checking the condition is accepted as the first parameter of a basic for loop, which accepts it.

Condition :

The Second parameter of a fundamental for loop defines the expression , if the check expression is true, the loop iterates further; otherwise, it stops and move out of the loop.

Updation :

A basic for loop’s third parameter specifies whether to increment or decrement the conditional variable that iterates the code in response to the condition.

Body of for loop :

Body  is known as a group of statements, such as variables, functions, etc.
When an iteration is successful, these are automatically carried out, and they continue to do so until the condition is not met.

Use of Do-While loop in C

Example:

Run
#include<stdio.h> 

int main() {

    int i = 0; // initialization

    do{
        printf("PrepInsta\n");

        i++; // updation
    }

    while (i <= 4); // condition

    return 0;
}

Output:

PrepInsta
PrepInsta
PrepInsta
PrepInsta
PrepInsta

For more related content : Click-Here