Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 274
Drew Avatar asked Nov 20 '11 22:11

Drew


1 Answers

You want to use break n

break 2;

After clarification, looks like you want continue 2;

like image 151
Eric Avatar answered Sep 19 '22 13:09

Eric