Re: New switch/case idea

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

This switch has fallthru turned on, therefore, if you want to stop processing, then you must type break. The above example would print 1, 2, 3, 4, 5.

How?

If x = 1, as stated, the "case 1:" is triggered, but why is 2,3,4,5 triggered??

LOL! grin I was confused too, Kat. Jeremy cleared it up for me. I don't recall if it was here on the forum or on the dev's list. Basically, after the first case is met, ALL following case bodies are run, disregarding the case statement, unless a break is encountered after which it leaves the switch construct.

I'm sure someone will post a better explanation here shortly.

This is a good reason to have a very clear explanation of switch in the docs... smile

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.

useless

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

Search



Quick Links

User menu

Not signed in.

Misc Menu