But maybe the PICBASIC people could add the CASE x TO y variety that some BASICs have.
But maybe the PICBASIC people could add the CASE x TO y variety that some BASICs have.
caverman, Why make a mountain out of a Mole hill. Just do this:
select case PulseLength
case is < 165
you don't want these values because they are below 165 so do something
case is < 176
OutValue=0
case is < 184
you don't want these values because they are between 176 and 184 so do something
case is < 192
OutValue=1
case else
you don't want these values because they are between 192 and 255 so do something
end select
This is the correct way as far as I can see to do this type of compare situation. If you were to use "IF" statements and try to capture all posibilities the code would look much different.
Dave Purola,
N8NTA
Why not using the statement below?
IF PulseLength > 165 AND PulseLength < 176 THEN
OutValue=0
ELSE
IF PulseLength > 184 OR PulseLength < 192 THEN OutValue=1
ENDIF
----------------------
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Because the above compiles almost 2.5 times longer!Originally Posted by sayzer
Ioannis
If you meant the size in terms of the words used,
I had 103 words with "IF" statement and 110 words with "Select Case" statement.
How did you have 2.5 times more words?
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
sayzer, You are right, it maybe smaller but you have only captured half of the cases. What are you going to do about the rest of the cases ie: < 165, > 176 but < 184, and > 192?
Dave Purola,
N8NTA
Hi!Originally Posted by sayzer
With the F877 chip I got 43 and 114 for the two codes.
What chip did you try?
Generally you have to keep the if statements as "thin" as possible. An AND can be replaced by one more IF resulting in less words.
Ioannis
Bookmarks