| while This statement will execute the instructions in a loop for as long as a condition, set by the given code, remains true. When the conditions change to false, the given alternate code will be executed, thus breaking out of the loop. The condition (true or false) is tested at the begining of the loop. It is conceivable, then, that the chunk of code within the loop may never be executed. An absolute imperative when using this statement is that the expression that makes up the condition must have one or more aspects of its value available to be changed during the course of the execution. If no changes are allowed to take place, the loop will become infinite. syntax: while (condition) { statements } EXAMPLE var n = 0 while (!document.forms[0].elementName[n].checked) { n++ } This example shows that a variable, n, is originally set to a value of '0', as given by the variable declaration 'var n = 0'. The while conditions retrieve the true or false status of the elementName[n], which in this case was whether or not a check box was checked or not. To allow a change to take place, and thus making the while statement not infinite, the value of 'n' was incremented by one using the 'n++' ('increment by one') statement. |