Main reason why Select Case is faster than using multiple IF's is because not all conditions are checked, only the first true condition in a Select Case argument has its underlying block of code executed.
That's my theory on it anyway.
Main reason why Select Case is faster than using multiple IF's is because not all conditions are checked, only the first true condition in a Select Case argument has its underlying block of code executed.
That's my theory on it anyway.
unless your using a little bit of your brain, it's true.
V2Code:plah plah plah Avar=Whatever Gosub StartSelectCase plah plah plah ' ' ' StartSelectCase: If AVar=1 then Dosomething Return Endif If AVar=2 then Dosomething Return Endif ' ' ' If AVar=x then Dosomething Endif Return
Sort of what's under the SelectCase hood.Code:AVar = Whatever StartSelectCase: If AVar=1 then Dosomething Goto EndSelectCase Endif If AVar=x then Dosomething Goto EndSelectCase Endif ' ' ' If AVar=y then Dosomething Endif EndSelectCase:
Now depending how the compiler, language interpret/optimise it, one can be faster than the other. It's hard to tell which will ALWAYS be faster so far as there's millions (and more) different possible itteration/conditions.
Both get the job done! One is easier to read, implement debug.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Pretty sure you'll find that for every IF argument, unlike Select Case, the subject variable to compare with is loaded into a working register each time.
However with Select Case it's already there for the next compare. Possibly the closed analogy of Select Case would be ELSEIF. But it's no where near as flexible unfortunately.
<br/>
Last edited by T.Jackson; - 7th May 2007 at 02:58.
Back to the original topic. Here's an interesting MicroChip on-line flash tutorial.
http://techtrain.microchip.com/x14/
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks