5.6.3.4. Breaking Out of a Loop

Statement

  break;
causes the innermost loop (or switch) that contains it to stop, and causes the program to move to just after that loop or switch. 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(long n)
  {
    long i;
    for(i = n+1; ; i++)
    {
      if(isPrime(i))
      {
        break;
      }
    }
    return i;
  }

Caution. You can use break to break out of a loop (of any kind) or a switch statement. But it does not work to get out of a function. For that, use return.