Node JS While Loop - Node js tutorial




While Loop:

  • While loop is an important in control flow statement.
  • It allows code to be executed based on a Boolean condition.
  • It is equivalent to repeating if condition statement.
  • The expression in while block evaluated first before starting the code execution.
  • If the expression returns true, the block code is executed else not. It is termed as pre-test loop.

Syntax :

while (condition) 
{
  	\\block of code to execute until the condition in the while satisfies
}
 nodejs loop

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

Read Also

While Loop C

Sample Code :

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

Code Explanation :

 nodejs while loop code

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

  • x is declared as 0.
  • The while part checks the condition as x is not equal to 5 as while (x!=5);
  • The loop block 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)";.

Output :

  • Executing the while loop in the nodejs framework produces the output of the variable x:
 nodejs while loop output

Learn Nodejs - Nodejs tutorial - nodejs while loop output - Nodejs examples - Nodejs programs

Read Also

Python While Loop


Related Searches to Node JS - While Loop - Node JS tutorial

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×