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 :

Use of Do-While loop in C

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.

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

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription