January 2003
Beginner to intermediate
1200 pages
23h 42m
English
There's another form of the while loop available: the do...while loop. This loop is much like the while loop, except that it checks the loop condition at the end, after the code in the loop has been executed, not at the beginning. Here's what this loop looks like in outline:
do {
code
} while (condition)
Actually, there's a big difference between the while and do...while loops in programmatic terms: The code in a do...while loop is always executed at least once, although that's not true of a while loop. Take a look at this example:
var number = 25
do {
document.writeln("The reciprocal of "
+ number + " is "
+ 1/number + "<BR>")
--number
} while (number > 0)
Here I'm displaying a sequence of reciprocal values, from ...