Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022

The while Loop

A loop structure allows you execute a series of statements over and over. Several kinds of loop structures are available in Java Script, the while loop evaluates an expression, and while the expression evaluates to true, the while loop will repeatedly execute the series of statements. The syntax for the while loop is shown below.

while(condition)
{
   statements;
}

An example of a while loop is shown below.

var price = 10.00;

while(price > 5.00)
{
   price -= 1.00;
}

alert("The final price is: " + price);

The Condition expression inside the brackets is evaluated. The result of that evaluation can be true or false. If the result is true the statements inside the curly brackets will be executed. If the result is false, the loop terminates and program flow continues with the next statement following the while loop structure.

In the example above, the variable price is initialized to 10.00. The Condition expression inside the while brackets tests the value of price to see if it's greater than 5.00. If the value of price is greater than 5.00, the statements inside the curly brackets are executed; 1.00 is subtracted from price. The condition expression again tests the value of price.

After the statements inside the curly brackets are executed five times, the value of price is no longer greater than 5.00. The result of the condition expression evaluation becomes false, the while loop terminates.

program flow continues with the next statement following the while loop structure, which creates a message box displaying the final value of price (5.00).

RSS Feed RSS Feed



Follow Stephen Bucaro Follow @Stephen Bucaro


Web Design Sections

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2017 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268