Forum und email

break

break termina l'esecuzione di una struttura for, foreach, while, do-while o switch.

break accetta un argomento opzionale che definisce, nel caso di cicli annidati, il livello del ciclo che è da interrompere.

<?php
$arr 
= array ('uno''due''tre''quattro''stop''cinque');
while (list (, 
$val) = each ($arr)) {
    if (
$val == 'stop') {
        break;    
/* Qui si può anche usare 'break 1;'. */
    
}
    echo 
"$val<br />\n";
}

/* Uso dell'argomento opzionale. */

$i 0;
while (++
$i) {
    switch (
$i) {
    case 
5:
        echo 
"At 5<br />\n";
        break 
1;  /* Interrompe solo awitch. */
    
case 10:
        echo 
"At 10; quitting<br />\n";
        break 
2;  /* Interrompe switch e while. */
    
default:
        break;
    }
}
?>