About EasyMorph Tutorials & Examples Web-help

New instruction SWITCH CASE

it would be useful to have, in extended espression syntax, the new instrucion switch / case like in C#
switch (caseSwitch)
{
case 1:
Console.WriteLine(“Case 1”);
break;
case 2:
Console.WriteLine(“Case 2”);
break;
default:
Console.WriteLine(“Default case”);
break;
}

We thought about this, but whatever idea for SWITCH/CASE syntax we came up with was only marginally better than what is already available:

IF case1 THEN ....
ELSE
IF case2 THEN ....
ELSE
...

Functional syntax (such as in F#) is pretty convenient, but I’m not sure if it’s sufficiently user friendly:

match A with
| case1 -> expression1
| case2 -> expresison2
| _ -> defaultExpression

The first choice is definitely userflendy and can be fine when you have a few IF… THEN (maximum 10).
But a more synthetic syntax like the second (F#) might be useful when dealing with 100 or more Choiches.
For example, I felt that I had to make several replacements (about fifty) and, not knowing yet about the beta extended espression syntax, I had nested 50 IF one inside the other … IF (a=1, x=“uao”, (IF a=2, x=“wow”, … ))
So the syntax like F# is interesting:
match A with
| case1 -> expression1
| case2 -> expresison2
| _ -> defaultExpression

To learn more about EasyMorph visit easymorph.com.