Re: New switch/case idea

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

NONONONO!!!!!!!!!!! WAY NOOOOOO

Case is "if" eye candy, no way should another case be run! If all the remaining case bodies run regardless of the case line, then this construct is next to me... errr, useless.

Kat, the example works that way because it has the clause with fallthru on the switch line. If one does not want it to fall through then do not use that clause. In which case only the one case block is executed.

-- WITH FALLTHRU EXAMPLE --- 
X=1 
switch X with fallthru do 
    case 1: ? 1 
    case 2: ? 2 
    case 3: ? 3 
    case 4: ? 4 
    case 5: ? 5 break 
    case 6: ? 6 
    case 7: ? 7 
end switch 
-- OUTPUT: 1 2 3 4 5 
-- WITHOUT FALLTHRU EXAMPLE --- 
X=1 
switch X do 
    case 1: ? 1 
    case 2: ? 2 
    case 3: ? 3 
    case 4: ? 4 
    case 5: ? 5 break 
    case 6: ? 6 
    case 7: ? 7 
end switch 
-- OUTPUT: 1 

The with fallthru clause helps in those rarer situations in which a given input is required to trigger multiple case blocks.

Does that help?

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

Search



Quick Links

User menu

Not signed in.

Misc Menu