'break' from a switch, then 'continue' in a loop

Drew picture Drew · Nov 20, 2011 · Viewed 8.8k times · Source

Is it possible to break from a switch and then continue in a loop?

For example:

$numbers= array(1,2,3,4,5,6,7,8,9,0);
$letters = array('a', 'b', 'c', 'd', 'e', 'f', 'g');

foreach($letters as $letter) {
    foreach($numbers as $number) {
        switch($letter) {
           case 'd':
               // So here I want to 'break;' out of the switch, 'break;' out of the
               // $numbers loop, and then 'continue;' in the $letters loop.
               break;
        }
    }

    // Stuff that should be done if the 'letter' is not 'd'.

}

Can this be done, and what would the syntax be?

Answer

Eric picture Eric · Nov 20, 2011

You want to use break n

break 2;

After clarification, looks like you want continue 2;