break [C++ Reference]
Keywords: keywords,break
Date: 2008-10-14T15:42:04-0700

[[break]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## break

The break keyword is used to break out of a do, for, or while loop. It is also used to finish each clause of a switch statement, keeping the program from “falling through” to the next case in the code. An example:

         while( x < 100 ) {
           if( x < 0 )
             break;
           cout << x << endl;
           x++;
         }

A given break statement will break out of only the closest loop, no further. If you have a triply-nested for loop, for example, you might want to include extra logic or a goto statement to break out of the loop.

Related Topics: continue, do, for, goto, switch, while

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •