C++ Syntax: break

Description

break may only be used inside a loop, such as a for loop, or a switch statement. It terminates the loop or switch. For example to search for the first zero in the array my_ints:-
for (Int_t index=0; index<10; index++) {
  if ( ! my_ints[i] ) 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