Re: New Switch Idea
- Posted by mattlewis (admin) Mar 27, 2009
- 1133 views
- <valuelist> is a comma-separated list of one or more discrete values that <expr> can equal to.
I thought that we had decided to add things like this in 4.1? If we do that now, I believe we are changing switch quite a bit and are going to push back 4.0 further. Adding them later on does not change the syntax for switch, it will only make some things easier.
- <statements> is a block of one or more euphoria statements. A zero length statement block is not allowed.
I personally, really liked the idea given by Matt, as copied from C#, of a smart switch that allowed:
switch X do case 1: case 2: case 3: -- do something end switch
Now, with your full proposal of allowing case 1,2,3: I guess the smart switch does make less sense to be excited about because you solve the same problem with allowing a list of items, then the block of code. I am assuming that case 1,2,3 would be written the same as the IL code of case 1: case 2: case 3: ?
Making the cases accept a comma delimited list is probably easier to do than to allow configurable fall through. And yeah, it should look the same from an IL point of view.
- If 'without fallthru' is in operation, once <statements> block is executed, control passes to the 'end switch' line. Any 'break' statements are ignored.
Why ignore a break? What if there were some condition in place that the user wanted to break from?
Yes, I don't understand this either. Unless Derek means when break is the last statement before the next case, at which point, I'd probably implement it to skip emitting the 'auto-break'. Six of one, half dozen of the other.
Matt