Switch Syntax Error


Trying to go through The Switch syntax Error but can't get it to work

Have entered case and break as follows

$fruit = "Apple";

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


But I get an error - Oops, try again. Make sure you add the default case!

Can anyone explain where I'm going wrong



switch (n) {
    case label1:
        code to be executed if n=label1;
    case label2:
        code to be executed if n=label2;
    case label3:
        code to be executed if n=label3;
        code to be executed if n is different from all labels;

in ths syntax you can see default case.
in your need that.The default statement is used if no match is found.


Thanks - eventually got it sorted - now stuck on While Loops Syntax


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.