I do not get "5. Using 'Endswitch'. Syntactic Sugar!"


#1

First of all to get it out of the way this is my code:







<?php
$i = 5;

switch ($i): {
    case 0:
        echo '$i is 0.';
        break;
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
        echo '$i is somewhere between 1 and 5.';
        break;
    case 6:
    case 7:
        echo '$i is either 6 or 7.';
        break;
    default:
        echo "I don't know how much \$i is.";

        endswitch;
}
?>
</body>

Now I just don't get the alternative syntax. I've placed the

switch ($i) {

and the

endswitch;

in an verity of places, but my code doesn't work. I look at the side bar to help and it doesn't help me one bit. I'd appreciate any help I receive and thank you all for your time.


#2
<?php
    $i = 5;

    switch ($i): 
        case 0:
            echo '$i is 0.';
            break;
        case 1:
        case 2:
        case 3:
        case 4:
        case 5:
            echo '$i is somewhere between 1 and 5.';
            break;
        case 6:
        case 7:
            echo '$i is either 6 or 7.';
            break;
        default:
            echo "I don't know how much \$i is.";

    endswitch;
?>

#3

That worked thanks, but can you tell me why it worked compared to mine?


#4

with the switch/endswitch there is no need for the {} braces in you case you put the braces after the switch/endswitch statement

switch($cond):  
    case:
    default:
endswitch;

#5
switch: 
....
...
 endswitch;

or

switch{
...
....
}

you can use any one to close the switch statement.