Using break to avoid division by zero : break statement « Statement « PHP






Using break to avoid division by zero

 
<?php

$counter = -3;

for (; $counter < 10; $counter++){
    if ($counter == 0){
        echo "Stopping to avoid division by zero.";
        break;
    }

    echo "100/$counter<br />";
}

?>
  
  








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.The break command applies to both loops and switch/case statements
8.break within a for loop