The break Statement

When a break statement is encountered, execution jumps outside the innermost loop or switch statement. You've seen that this is essential to the usefulness of switch statements. It also has some application for loops. There are cases when you need to leave a loop block somewhere in the middle. Listing 3.6 shows this in action.

Listing 3.6. Leaving a Loop Using break
<?
  while(true)
  {
    print("This line is printed.");
    break;
    print("This line will never be printed.");
  }
?>

Get Core PHP Programming: Using PHP to Build Dynamic Web Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.