Changes

JavaScript Flow Control and Looping

780 bytes added, 13:43, 24 April 2007
JavaScript ''do ... while'' loops
=== JavaScript ''do ... while'' loops ===
 
Think of the ''do ... while'' loop as an inverted ''while'' loop. As shown above, the ''while'' loop evaluates an expression before executing the code contained in the body of the loop. If the expression evaluates to ''false'' on the first check then the code is not executed. The ''do .. while'' loop is provided for situations where you know that the code in your loop will ''always'' need to be executed at least once. For example you may want to keep asking a user to fill in a field in a prompt dialog until specific text is entered. You know that you have to show the prompt dialog at least once to get a string from the user to evaluate against. The syntax for the ''do ... while'' loop is as follows:
 
do
{
\t''JavaScript statement''
} while (''conditional expression'')