×

php · level 1 · unit 5 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

stops a loop early. skips a turn.

Sometimes you want out before the loop is done. break stops the loop on the spot, and PHP carries on with the first line after it.

continue is gentler. It skips the rest of this go and jumps straight to the next one, so the loop keeps running.

Both usually sit inside an if, so they only happen when you want. In this lift, continue skips unlucky floor 13 but stops at all the others.

<?php
for ($floor = 12; $floor <= 15; $floor++) {
    if ($floor === 13) {
        continue;
    }
    echo "Ding! Floor $floor\n";
}

break and continue only work inside a loop, so PHP refuses to run them anywhere else.