if ( $time == 3 ) { print("3pm"); }
else if ( $time > 3 ) { print("After 3pm"); }
else { print("Anytime but 3pm"); }
switch ($time) {
case 3: print("3pm"); break;
default: print("Anytime but 3pm");
}
when($time) {The Switch statement can't evaluate conditions; so, the expression >3 (greater than 3) is not possible. The When statement can handle multiple conditions like the Switch statement, and it can evaluate conditions like the If-else statement. This effectively allows the When statement to replace both the If-else statement and the Switch statement in traditional programming languages. Furthermore, this produces less overhead and better organization of logic blocks.
3: print("3pm");
>3: print("After 3pm");
else: print("Anytime but 3pm");
}
Additionally, the When statement can evaluate multiple parameters.
when ($time, $space){
$time > 3: print("It's afternoon");
$space != $time: print("space and time are not equivalent");
else: print("This is the default option");
}
** Could also be called the monty_switch in reference to my last name.