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.2 while Loop

For many programming tasks, you’ll need to perform the same operation repeatedly (e.g., adding a group of numbers to find their sum). To perform operations repeatedly, you’ll need to use a loop statement. JavaScript provides three types of loop statements—while loop, do loop, and for loop. We’ll cover the while loop in this section, and the do and for loops later in the chapter.

Syntax and Semantics

The while loop is the most flexible of the three types of loops. You can use it for any task that needs repetitive operations. FIGURE 10.1 shows the syntax and semantics for the while loop. The syntax at the left of the figure should look familiar because it’s similar to the if statement syntax. In the while loop’s heading, after ...

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