C++ Syntax: break

Description

break may only be used inside a loop, such as a for or while loop, or a switch statement. It terminates the loop or switch. For example to search for the first zero in the array my_ints:-
Int_t index;
for (index=0; index<10; index++) {
  if ( ! my_ints[index] ) break;
}
if ( index == 10 ) cout << "my_ints contains no zeros" << endl;
else               cout << "the first zero in my_ints is at " << index << endl;

Where switch and loop statements are nested, break exits the innermost one containing it.

Usage Notes

None.
Go Back to the The C++ Crib Top Page


If you have any comments about this page please send them to Nick West