|
Statement
break;causes the innermost loop that contains the break statement to stop immediately, moving the program to just after that loop. For example, suppose that you have a function isPrime(n) that yields true if integer n is prime and false if not. Then the following function returns the smallest prime number that is greater than n.
long nextPrime(const long n) { long i; for(i = n+1; true; i++) { if(isPrime(i)) { break; } } return i; }
Caution. You can use break to break out of any kind of loop. But break does not work to get out of a function. For that, use return.
|