Re: New switch/case idea

new topic     » goto parent     » topic index » view thread      » older message » newer message
DerekParnell said...
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?

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!

useless

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

Search



Quick Links

User menu

Not signed in.

Misc Menu