Re: New switch/case idea

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

I want fall through to be the default or at least make easy to enable with a single command.

It will be easy to use fall through. It looks like the final result will probably be something like:

switch x with fallthrough do 
    case 1 then 
    ... 
end switch 

There are still some details to be worked out with respect to Fernando's idea. On the dev list, I proposed a slight modification:

switch x do -- NOTE: no fall through by default 
    case 1 then 
       ... 
    -- NOTE: no fall through here 
    case 2,3 then 
 
    -- this one falls through 
    case 4 continue then 
 
    -- also fall through here 
    case else continue 
end switch 

The main change was to move the continue to where the actual fall through is happening. We could put the continue before the case, but I think that could lead to bugs when the coder really wants to use continue to go to the next loop iteration:

for i = 1 to n do 
    switch x[i] do -- NOTE: no fall through by default 
        case 1 then 
           ... 
           continue -- we want to skip "other stuff" at the bottom 
        -- NOTE: no fall through here 
        case 2,3 then 
       
        -- this one falls through 
        case 4 continue then 
 
        -- also fall through here 
        case else continue 
    end switch 
    ... do other stuff ... 
end for 

Matt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu