• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Using do…while Loops

JavaScript 1.2 introduced a third type of loop: the do…while loop. This type of loop is similar to an ordinary while loop, with one difference: the condition is tested at the end of the loop rather than the beginning. Listing 8.3 shows a typical do…while loop.

Listing 8.3 An Example of a do…while Loop

1: do {
2: n++;
3: total += values[n];
4: }
5: while (total < 10);


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint