Node JS Do While Loop - Node JS tutorial



Do While Loop

  • The do statement executes a statement or a block of statements repeatedly until a specified expression evaluates to false.
  • The body of the loop must be enclosed in braces, {}, if it consists of a single statement.
  • It is also called as exit-condition loop.

Syntax :

do {
   do_work();  
} while (condition);
 nodejs dowhile

Learn Nodejs - Nodejs tutorial - nodejs dowhile - Nodejs examples - Nodejs programs

Read Also

Do While Loop in C

Sample Code :

var x=0;
do {
x++;
console.log("The value of x is : "+x);
}
while (x!=5);

Code Explanation :

 nodejs dowhile loop code

Learn Nodejs - Nodejs tutorial - nodejs dowhile loop code - Nodejs examples - Nodejs programs

  • x is declared as 0.
  • Do while loop is stated with incrementing x value as x++ and the same is sent for output to console with the line of code “console.log("The value of x is : "+x);".
  • Finally the while part checks the condition as x is not equal to 5 as while (x!=5);a block of code for one time and check the condition.

Output :

Executing the do while loop in the nodejs framework produces the output of the variable x.

 nodejs dowhile loop code output

Learn Nodejs - Nodejs tutorial - nodejs dowhile loop code output - Nodejs examples - Nodejs programs


Related Searches to Node JS Do While Loop - Node JS Tutorial