do while loop in javascript with examples

do while Loop in JavaScript:

do while in JavaScript, this will execute code block once and then check for condition, and will run another iteration if condition is true, otherwise terminate do while loop

//Syntax:
 
 do
  {
  code block to be executed
  }
while (condition);
    
//Example:

var x=0,i=0;
do
  {
  x=x +  i ;
  i++;
  }
while (i<5);
alert(x);

 

Leave a Reply