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

Chapter 8. Loop Statements > The do-while Loop

8.3. The do-while Loop

As we saw earlier, a while statement allows the interpreter to execute a block of code repeatedly while a specified condition remains true. Due to a while loop's structure, its body will be skipped entirely if the loop's condition is not met the first time it is tested. A do-while statement lets us guarantee that a loop body will be executed at least once with minimal fuss. The body of a do-while loop always executes the first time through the loop. The do-while statement's syntax is somewhat like an inverted while statement:

do {
  substatements
} while (condition);


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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