Select Case is a lot like a "Load of IF's" with a few differences.The same functionality using IF statements would look like this ...
- It removes some of the (n00besque content contained) look and feel.
- Only the first "CASE" that evaluates TRUE will execute, then it exits the SELECT block.
In your list of IF's, if the first one is true, it still goes on and evaluates all the other IF's too.
This allows more complex logic, where more than one test can be true, but only the first one is acted on.OR, if you have PBP 2.60 you could do it like this ...Code:IF MYBYTE = 1 THEN HIGH LED1 ELSE IF MYBYTE = 2 THEN HIGH LED2 ELSE IF MYBYTE = 3 THEN HIGH LED3 ELSE IF MYBYTE = 4 THEN HIGH LED4 ELSE IF MYBYTE = 5 THEN HIGH LED5 ELSE IF MYBYTE = 6 THEN HIGH LED6 ENDIF ENDIF ENDIF ENDIF ENDIF ENDIFIt may not seem like much difference with this simple example, but with large SELECT CASE blocks using more complex comparisons, it can save a boat load of execution time not having to evaluate every condition.Code:IF MYBYTE = 1 THEN HIGH LED1 ELSEIF MYBYTE = 2 THEN HIGH LED2 ELSEIF MYBYTE = 3 THEN HIGH LED3 ELSEIF MYBYTE = 4 THEN HIGH LED4 ELSEIF MYBYTE = 5 THEN HIGH LED5 ELSEIF MYBYTE = 6 THEN HIGH LED6 ENDIF
* SELECT CASE is also much easier to read. Especially when it's not your program.
PicBasic Pro, was written to generate the Smallest and Fastest code possible. As it is the HIGH/LOW statements only use a couple of instruction cycles. If you add in the abilities to use them like array's and access pins non-contiguously, it would make EVERY HIGH/LOW statement Bigger and Slower, breaking everyone's code, and causing more complaints than not having those abilities produces.





Bookmarks