Re: New switch/case idea

new topic     » goto parent     » topic index » view thread      » older message » newer message
Kat said...

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 

I see. Of course its not English, but it could still be read kinda like...

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 start here and print 1 
                -- no fallthru so exit the switch 
    case 2: ? 2 -- in the case where x=2 then start here and then print 2 
                -- no fallthru so exit the switch 
    case 3: ? 3 -- in the case where x=3 then start here and then print 3 
                -- no fallthru so exit the switch 
    case 1,2: ? "1 or 2" -- error: these cases are already covered above. 
end switch -- return to linear code flow 
Kat said...
DerekParnell said...

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 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.

The only thing that doesn't work like you might've expected is the situation of coding a case value more than once. This is not really allowed. Otherwise the switch should work as before. There is no reason to return to a series of if-elsif statements.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu