Changes

JavaScript Flow Control and Looping

12 bytes added, 17:56, 26 May 2007
JavaScript ''while'' loops
The ''for'' loop described above works well when you know how many times a particular task needs to be repeated. Clearly there will often be instances where something needs to be repeated until a certain condition is met, with no way of knowing how many repetitions are going to be needed to meet that criteria. To address this need JavaScript provides the ''while'' loop. In essense the ''while'' loop repeats a set of tasks until a specified condition is met. The ''while'' loop syntax is as follows:
<pre
while (''condition'')
{
''JavaScript Statements''
}
</pre>
where ''condition'' is an expression that will return either ''true'' or ''false'' and ''JavaScript Statements'' represents the JavaScript to be executed while the expression is ''true''. For example: