note 13706 modified in control-structures.switch by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 13:55:00 +0000 |
| Subject: | note 13706 modified in control-structures.switch by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79927@lists.php.net to get a copy of this message | ||
It's obvious, but might still bear explicit mention that you can conditionally execute the
BREAK statement in order to allow a CASE to fall through to the next CASE.
e.g.:-> Here, CASE 1 will fall through and the DEFAULT CASE statements will also be executed
unless $somevar is true.
<?php
switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
if ($somevar) {
break;
}
default;
echo 'Some Default Statements';
break;
}
?>
Cheers,
Ben Nardone
--was--
It's obvious, but might still bear explicit mention that you can conditionally execute the
BREAK statement in order to allow a CASE to fall through to the next CASE.
e.g.:-> Here, CASE 1 will fall through and the DEFAULT CASE statements will also be executed
unless $somevar is true.
switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
if ($somevar) {
break;
}
default;
echo 'Some Default Statements';
break;
}
Cheers,
Ben Nardone
http://php.net/manual/en/control-structures.switch.php