Switch Case : Doubts
Ok,I got to clear 2 doubts associated with the classic "Switch Case"-
1)What "break" does is exits the case and brings to the end of switch case,I have omitted "break" from case "red"..So it comes to case "blue" but it should only enter case "blue" when it is true(which is not,right now),right?,then why my output is like this-
Output::
Your favorite color is red!Your favorite color is blue!
2)When I shifted default after case "red" and omitted break from case "red" it was executing default too!(Why?),but when I shifted default at the top of the block it was not executing.
<?php
$favcolor="red";
switch ($favcolor)
{
default:
echo "Your favorite color is neither red, blue, or green!";
case "red":
echo "Your favorite color is red!";
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
?>
Output::
Your favorite color is red!Your favorite color is blue!
2)When I shifted default after case "red" and omitted break from case "red" it was executing default too!(Why?),but when I shifted default at the top of the block it was not executing.
0