Can you post a readable example using either IF's or Select Case?
That's a shame Jeremy, I was going to expose you to the world as border line genius.
Last edited by T.Jackson; - 19th June 2008 at 17:37.
One possible "improved" solution is as follows ...
That code will do exactly the same job as ...Code:Select Case b1 Case Is < 219 timerN = 3 timerAc = 120 timerBc = 60 Case Is < 243 timerN = 2 timerAc = 180 timerBc = 60 Case Is <= 255 timerN = 1 timerAc = 600 timerBc = 180 End Select
BUT, it'll probably compile to half the size, run twice as fast, be more readable, easier to comprehend and definitely far easier to maintain.Code:If (b1 <= 255 And b1 >= 243) Then timerN = 1 timerAc = 600 timerBc = 180 End If If (b1 <= 242 And b1 >= 219) Then timerN = 2 timerAc = 180 timerBc = 60 End If If (b1 <= 218 And b1 >= 193) Then timerN = 3 timerAc = 120 timerBc = 60 End If
Regards,
Trent Jackson
Last edited by T.Jackson; - 20th June 2008 at 17:44.
I might add also that the same thing is possible using IF's, select case is always more effcient though however.
Notice how we start with the smallest number first? Always start with the smallest value first and work downwards with the next biggest value.Code:for (int i = 0; i < 12; i++) { sample = tempArray[i]; if (sample < 0) rangeA++; else if (sample < 10) rangeB++; else if (sample < 20) rangeC++; else if (sample < 30) rangeD++; else rangeE++; }
Hope it helps
Trent Jackson
i'm new to picbasic.
i didn't know that the "select" statment is so faster and smaller than many "if then" compiled in picbasic [realy i did not look at the select statment... i've just used the first think i know in picbasic]. it was my mistake that i does't look at the beutiness of my code... even in functions where performance are not needed (like the selection of the time).
i've just share my code.
anyway, thank for suggestions.
any other suggestion will be apriciated.
p.s. is this code more faster? (no IF needed)
LOOKDOWN2 W0,>[255,242,218,192,166,144,124,105,80,59,49,40,0],B0
LOOKUP2 B0,[60,600,180,120,60,60,40,30,20,15,10,45,30],timerAc
LOOKUP2 B0,[60,180,60,60,60,30,40,30,20,15,10,15,15],timerBc
LOOKUP2 B0,[6,1,2,3,4,5,6,7,8,9,10,11,12],timerN
Last edited by hozone; - 20th June 2008 at 21:14.
What
is
so
hard
to
read
with
colons
?
I
think
they
help
make
the
code
MORE
readable
if
used
in
the
right
place.
It
makes
it
more
like
reading
a
book.
![]()
Dave
Always wear safety glasses while programming.
Bookmarks