The While Loop In JavaScript

JavaScript includes while loop to execute code repeatedly till it satisfies a specified condition. Unlike for loop, while loop only requires condition expression.

Syntax:

while(condition expression)
{
    /* code to be executed 
    till the specified condition is true */
}

Example

In the following example, the code in the loop will run, over and over again, as long as a variable (i) is less than 10:

while (i < 10) {
    text += "The number is " + i;
    i++;
}

 

The Do/While Loop In JavaScript

JavaScript includes another flavour of while loop, that is do-while loop. The do-while loop is similar to while loop the only difference is it evaluates condition expression after the execution of code block. So do-while loop will execute the code block at least once.

Syntax:

do{

    //code to be executed

}while(condition expression)
        

Example

The example below uses a do/while loop. The loop will always be executed at least once, even if the condition is false because the code block is executed before the condition is tested:

do {
    text += "The number is " + i;
    i++;
}
while (i < 10);

 

 

Working hours

 

Day Timing
Monday To Friday 8:00 Am To 8:00Pm
Saturday & Sunday 8:00 Am To 5:00Pm
 
 

Contact Information
ADDRESS: 263, First Floor
Pocket H-17, Sector 7
Rohini, Delhi - 110085
Near Rohini West Metro Station
Opposite Metro Pillar No. 425

Email: contactbapugraphics@gmail.com
            bapugraphicsindia@gmail.com

Mobile: 9891222738

Copyright © 2014 Bapu Graphics, All Right Reserved.