Welcome to Bucaro TecHelp!

Bucaro TecHelp
HTTPS Encryption not required because no account numbers or
personal information is ever requested or accepted by this site

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

The do/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 do/while loop executes the statements inside the curly brackets one time first before the condition expression inside the whilebrackets are evaluated. The syntax for the do/while loop is shown below.

do
{
   statements;

}
while(condition);

An example of a do/while loop is shown below.

var price = 10.00;

do
{
   price -= 1.00;

}
while(price > 5.00);

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

The do/while loop is similar to the while loop except that the while loop evaluates the test condition first before executing the statements, but the do/while executes the statements first, then evaluates the test condition.

In the example above, the variable price is initialized to 10.00. The statements inside the curly brackets are executed; 1.00 is subtracted from price. 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 again; another 1.00 is subtracted from price. The Condition expression inside the while brackets tests the value of price to see if it's greater than 5.00.

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 do/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).

More Java Script Code:
• Remove Blank Spaces From Ends of a String
• Java Script Data Types
• The Screen Object
• Define Lines in a String
• Java Script Math.cos Method
• Java Script Strings
• Comparison Operators
• The switch / case Structure
• The Conditional Operator
• Java Script Math.tan Method

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro


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