note 29095 deleted from control-structures.switch by victor
| From: | victor@php.net | Date: | Wed, 05 Mar 2003 07:27:37 +0000 |
| Subject: | note 29095 deleted from control-structures.switch by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-44848@lists.php.net to get a copy of this message | ||
If I understand the comment from rmunn at pobox dot com correctly, the following example quoted from
the top of this page is ambiguous:
if ($i == 0) {
print "i equals 0";
}
if ($i == 1) {
print "i equals 1";
}
if ($i == 2) {
print "i equals 2";
}
switch ($i) {
case 0:
print "i equals 0";
break;
case 1:
print "i equals 1";
break;
case 2:
print "i equals 2";
break;
}
It would imply switch is equivalent to:
if ($i == 0) {
print "i equals 0";
}
if ($i == 1) {
print "i equals 1";
}
if ($i == 2) {
print "i equals 2";
}
if ($i == 1) {
print "i equals 1 again";
}
which, in this case, $i == 1 would be executed twice.
Switch() is actually equivalent to:
if ($i == 0) {
print "i equals 0";
}
elseif ($i == 1) {
print "i equals 1";
}
elseif ($i == 2) {
print "i equals 2";
}
elseif ($i == 1) {
print "i equals 1 again";
}
else
// this would be equivalent to 'default:'
where $i == 1 would be executed only once.