Re: New switch/case idea
- Posted by jimcbrown (admin) Apr 01, 2009
- 1839 views
Your first example is in error because x != 2,3,4, or 5, with or without fallthru.
That is not an error, that is the very nature of fallthru. Think of Duff's device.
The concept of fallthru is great where a situation is like:
X=1 switch X with fallthru do case 1: ? 1 case 2: ? 2 case 3: ? 3 case 1,2: ? "1 or 2" end switch
OUTPUT: 1 "1 or 2"
Kat, your example (despite the presence of "with fallthru") does not have fallthru.
You said:
The with fallthru clause helps in those rarer situations in which a given input is required to trigger multiple case blocks.
But the problem is, in the first example you gave, x is not 2,3,4, or 5, so they should not execute, just as if you had
X=1 switch X do case 2: ? 2 case 3: ? 3 case 4: ? 4 end switch
OUTPUT: none!
useless
Wrong. The way fall through works, once a case is matched, the blocks for that case and all cases after it are executed. That is how fall through works in C, Java, etc.
What you are asking for, is to disable fallthrough altogether.