contents   index   previous   next



The while statement is used to execute a particular section of code, over and over again, until an expression evaluates as false.


while (expression)





When the interpreter comes across a while statement, it first tests to see whether the expression is true or not. If the expression is true, the interpreter carries out the statement or statement block following it. Then the interpreter tests the expression again. A while loop repeats until the test expression evaluates to false, whereupon the program continues after the code associated with the while statement.


The following fragment illustrates a while statement with a two lines of code in a statement block.


while( ThereAreUncalledNamesOnTheList() != false)


   var name=GetNameFromTheList();




do {...} while