PHP do while loop statement with syntax and example

If specified condition is true, loop through block of code once and then repeat again and again.

Syntax of PHP do while loop:

Example:

Result:

Do while loop is known as exit control loop because it check the condition at last(on exit).

Do while loop executes at least once when if condition is false.

Do While Statement in C Programming

like a while statement,  “ do while statement” repeats a set of statements if condition is true.

If condition is false the flow of control do not enter inside the do-while loop.

“do-while” first execute the body of loop than tests the condition.

Means even if the condition if false do-while executes at least ones.

The syntax of a do…while loop in C programming language is −

Example: Write a program to print 1 to 10 using while loop.

#include int main() {int a = 1;do { printf(” %d \n”, a); a++; } while (a <= 10); // loop executes 10 times return 0; }

OUTPUT

Even if the condition if false do-while executes at least ones.

#include int main() { int a = 100;do { printf(” %d \n”, a); a++;} while (a <= 10); // condition is false even do-while executes ones return 0; }

OUTPUT