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

Chapter 8. Loop Statements > Stopping a Loop Prematurely

8.6. Stopping a Loop Prematurely

In a simple loop, the test expression is the sole factor that determines when the loop stops. When the test expression of a simple loop yields false, the loop terminates. However, as loops become more complex, we may need to terminate a running loop arbitrarily, regardless of the value of the test expression using the break statement. A related statement, continue, ends the current iteration of the loop body and resumes execution with the next iteration.

8.6.1. The break Statement

The break statement ends execution of the current loop or switch statement (as we saw in Chapter 7). It has the modest syntax:


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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