Changes

Jump to: navigation, search

JavaScript Flow Control and Looping

13 bytes added, 13:44, 24 April 2007
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:
<pre>
do
{
''JavaScript statement''
} while (''conditional expression'')
</pre>

Navigation menu