The break command applies to both loops and switch/case statements : break statement « Statement « PHP






The break command applies to both loops and switch/case statements

 
for ($i = 1; $i < 3; $i = $i + 1) {
            for ($j = 1; $j < 3; $j = $j + 1) {
                    for ($k = 1; $k < 3; $k = $k + 1) {
                            switch($k) {
                                    case 1:
                                            print "I: $i, J: $j, K: $k\n";
                                            break 2;
                                    case 2:
                                            print "I: $i, J: $j, K: $k\n";
                                            break 3;
                            }
                    }
            }
    }
  
  








Related examples in the same category

1.Break statement
2.Breaking a Loop
3.Using the break Statement
4.Break 1 or break 2
5.Break Statement
6.Using the break Statement
7.break within a for loop
8.Using break to avoid division by zero