Re: New switch/case idea
- Posted by Kat Apr 01, 2009
- 1818 views
The with fallthru clause helps in those rarer situations in which a given input is required to trigger multiple case blocks.
Does that help?
No.
Your first example is in error because x != 2,3,4, or 5, with or without fallthru. 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"
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!
I really do understand what you are saying, Kat.
Please try to understand what I'm saying. The switch statement is not syntax sugar for an if - elsif - endif series. The case clause is not an executing statement, it can be more thought of as a label.
Ok, i was reading it as english:
X=1 -- x = 1 switch X do -- switch from linear code flow to "in case" case 1: ? 1 -- in the case where x=1 then print 1 case 2: ? 2 -- in the case where x=2 then print 2 case 3: ? 3 -- in the case where x=3 then print 3 case 1,2: ? "1 or 2" -- if case is 1 or 2, print "1 or 2" end switch -- return to linear code flow
You are not being forced to use the fallthru clause if its against your coding needs or principles. In the same way the "goto" is one of your coding tools but others refuse to use it, the "with fallthru" clause is a tool that some may choose or use or not, as they see fit.
We have given you the goto because of your persistant pressure and valid arguments for its inclusion. Please see that with fallthru is another coding style much like the goto statement.
I am not objecting to it based on code flow redirection like goto does, i am objecting to it based on logic of not executing the case conditions. I did not realise it was a computed goto. I expected it was a stack of if-elsif- statements. I recoded a section of http.e to use switch based on how it worked 3 days ago, and the new code was beautiful short clean simplicity. It doesn't work that way now, and i must return that code to the stack of if-then statements it was. Or, rather, Jeremy must. Anyhow, i guess i have made my point, and it's not valid to make it work like it did work or how i'd like to see it work.
useless