Skip to Content
Real World XML
book

Real World XML

by Steven Holzner
January 2003
Beginner to intermediate content levelBeginner to intermediate
1200 pages
23h 42m
English
Peachpit Press
Content preview from Real World XML

Creating do…while Loops

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Inside XML

Inside XML

Steven Holzner
XML Hacks

XML Hacks

Michael Fitzgerald

Publisher Resources

ISBN: 0735712867Purchase book