Javascript While Loops

Updated on 01 Mar 2012,
Published on 10 Mar 2008

While loop in javascript works same like for loop in javascript but in a little bit different manner. While loop runs until the condition is true and exits when the condition is false.

JavaScript Basics Examples:

You can see the live samples and examples of JavaScript Basics from the following links:

Syntax of JavaScript While loop

while (var<=value)
{
    // code to be executed here;
}

Example of JavaScript while loop

    var i=1;
    
    while(i<=7)
    {
        document.write('<font size=\"' + i + '\">Hello World</font><br />');
        i++;
    }

Above example shows the use of while loop in JavaScript by executing a single line of code how you can increase the size of font in each loop by incrementing the value of variable i.

Output:

You can see the output of above discussed codes from the following link:

JavaScript While Loop

Continue to next tutorial: Javascript Do While to learn the alternate of using while loop in JavaScript.

0 Responses to "Javascript While Loops"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers