Re: Switch question - yet again!
- Posted by Spock Sep 28, 2016
- 10890 views
jessedavis said...
Spock said...
Try replacing the switch/case block with a normal if block.
If it works perhaps you could do the same replacement _everywhere_ in your code.. and discover, strangely, that your programs all seem to be working better..
Spock
Yes, I can do this. I have done it before and sworn on a stack of Bibles I wouldn't use switch again. I am weak. It was such a simple piece of code. How could I go wrong?
All this aside, switch does have some useful features that makes coding easier and, if implemented suitably, should be more efficient than other methods.
Wikipedia has some propaganda on the use of switch. In the very rare cases when I might need anything like it I do this:
while 1 do if x = a then .. end if -- fallthough here if x = b then .. exit end if -- break from block if x = c then .. end if exit end while
Slightly verbose but much safer and flexible ..
Spock