HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

The Do/While Loop

The do/while loop is a post-test loop in C, meaning the loop body is executed at least once before the condition is checked. This differs from the while loop, which checks the condition before executing the body.

Syntax

do {

// code block to be executed

}

while (condition);


The example below uses a do/while loop. With this powerful tool, you can ensure your code will always be executed at least once, no matter what. Say goodbye to endless debugging and hello to efficiency and reliability in your coding journey today!


Syntax

#include <stdio.h>

int main() {

int i = 0;

do {

printf("%d\n", i);

i++;

}

while (i < 5);

return 0;

}


Output

0

1

2

3

4


Do not forget to increase the variable used in the condition, otherwise the loop will never end!" while addressing the issues raised in the ratings and aiming for an even better result.