O'Reilly logo

Web Programming with HTML5, CSS, and JavaScript by Dean

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.5 do Loop

As mentioned earlier, JavaScript has three types of loops—the while loop, do loop, and for loop. Next up—the do loop.

Syntax and Semantics

Note the do loop’s syntax template at the left of FIGURE 10.6. It shows the do loop’s condition at the bottom. That contrasts with the while loop, where the condition is at the top. Having the condition tested at the bottom guarantees that the do loop executes at least one time. After all, the condition is the only way to terminate the loop, and the JavaScript engine won’t check the condition (at the bottom) until after executing the lines above it. In the syntax template, note the semicolon at the right of the condition. That’s also different from the while loop. Finally, note that the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required