Control Flow: Switch 3/6

Switch Syntax
switch statement is similar to an if / elifelse statement in that you can check multiple conditions. Here's what it looks like:
$myNum = 2;

switch ($myNum) {
    case 1:
        echo "1";
        break;
    case 2:
        echo "2";
        break;
    case 3:
        echo "3";
        break;
    default:
        echo "None of the above";
}
  1. switch statement is made up of theswitch keyword, a variable to check, and a pair of curly braces }. Here we check the value of$myNum.
  2. Then we have a case block for each comparison. For example case 1echo "1";breakchecks whether $myNum is equal to 1. If yes, it echos "1", and uses break to exit theswitch statement.
  3. Otherwise, the next case block runs.
  4. If all cases return false, the default case gets executed.
Instructions
On line 10, there's a switch statement
  1. Fill the __ spots with the correct code. Check out the example above
  2. Add the default case.
?
Hint
Test how well you're learning and fill in gaps with Codecademy Pro.Learn more.
You should replace the two __ with either the word break or case. Check out the example above to see where the defaultcase and break should go.
Control Flow: Switch 3/6
<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
    <?php
    $fruit = "Apple";

    switch ($fruit) {
        case "Apple":
            echo "Yummy.";
            break;
        default:
            echo "Yummy";

    }

    ?>
    </body>
</html>

Comments

Popular posts from this blog

MEGA 暫存檔案刪除

IOS GCD多執行緒

利用CMD指令強制刪除