Just had a sleep on this - I've never previously used case, and now I fresh look at it, to my eyes it's just a load of IFs?
For example....
Code:
HIGH_LED:
SELECT CASE MyByte
CASE 1 : HIGH LED1
CASE 2 : HIGH LED2
CASE 3 : HIGH LED3
CASE 4 : HIGH LED4
CASE 5 : HIGH LED5
CASE 6 : HIGH LED6
END SELECT
RETURN
could be written as...
Code:
IF MYBYTE = 1 THEN HIGH LED1
IF MYBYTE = 2 THEN HIGH LED2
IF MYBYTE = 3 THEN HIGH LED3
IF MYBYTE = 4 THEN HIGH LED4
IF MYBYTE = 5 THEN HIGH LED5
IF MYBYTE = 6 THEN HIGH LED6
So when to use case & when to use if?
Going back 20 years to when I used to write simple VMS DCL programs, I could construct code like thus...
HIGH "LED"+'MyByte'
the stuff inbetween " " was text & stuff in the ' ' was the value held in a variable
therefore the above would actually run as.....
HIGH LED1 (assuming MyByte held 1) ......presumably no similar ways of constucting in Picbasic?
Bookmarks