Email:info@beework.net
Sales:
0800 882 4173
Support:
0117 230 7000
Mobile:
07866 627185
International:
+44 (0)117 230 7000
Ready Made Solutions
Photographer website
Estate & letting agents
Events & ticket sales
Charities
Church website
Wedding day
Holiday let website
Bookmark with
Generates the JavaScript code for a while loop statement. Specify how many times you want the action to occur and click the Generate Code button.
while (condition) {
statements
}If the condition becomes false, the statements within the loop stops executing and control passes to the statement following the loop. The condition test occurs only when the statements in the loop have been executed and the loop is about to be repeated. That is, the condition test is not continuous but is performed once at the beginning of the loop and again just following the last statement in statements, each time control passes through the loop.
Example 1. The following while loop iterates as long as n is less than three:
n = 0With each iteration, the loop increments n and adds that value to x. Therefore, x and n take on the following values:
x = 0
while( n < 3 ) {
n ++
x += n
}
n < 3 is no longer true, so the loop terminates. Example 2: infinite loop. Make sure the condition in a loop eventually becomes false; otherwise, the loop will never terminate. The statements in the following while loop execute forever because the condition never becomes false:
while (n<3) {
alert("Hello, world") }