Re: New switch/case idea
- Posted by euphoric (admin) Apr 01, 2009
- 1788 views
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! 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...