ENDIF,IF, whats the difference?
lightsout
Posts: 22
Still a newbe.whats the difference· in these examples ? whay use ENDIF·or ELSEIF ?
value·· VAR···· Word
Main:
· DO
··· PULSIN 0, 1, value························· ' measure pulse input
··· DEBUG DEC value, CR
··· IF (value > 4000) THEN····················· ' evaluate duration
····· DEBUG "Value was greater than 4000"
··· ELSEIF (value = 4000) THEN
····· DEBUG "Value was equal to 4000"
··· ELSE
····· DEBUG "Value was less than 4000"
··· ENDIF
··· DEBUG CR, CR
··· PAUSE 1000
· LOOP
OR
value·· VAR···· Word
Main:
· DO
··· PULSIN 0, 1, value························· ' measure pulse input
··· DEBUG DEC value, CR
··· IF (value > 4000) THEN····················· ' evaluate duration
····· DEBUG "Value was greater than 4000"
··· IF (value = 4000) THEN
····· DEBUG "Value was equal to 4000"
····IF· (value < 4000) THEN
····· DEBUG "Value was less than 4000"
··· DEBUG CR, CR
··· PAUSE 1000
· LOOP
I re-read and re-read and I still don't get it unless it is just a matter of good code writing. Thanks!
Post Edited (lightsout) : 3/19/2005 10:00:50 PM GMT
value·· VAR···· Word
Main:
· DO
··· PULSIN 0, 1, value························· ' measure pulse input
··· DEBUG DEC value, CR
··· IF (value > 4000) THEN····················· ' evaluate duration
····· DEBUG "Value was greater than 4000"
··· ELSEIF (value = 4000) THEN
····· DEBUG "Value was equal to 4000"
··· ELSE
····· DEBUG "Value was less than 4000"
··· ENDIF
··· DEBUG CR, CR
··· PAUSE 1000
· LOOP
OR
value·· VAR···· Word
Main:
· DO
··· PULSIN 0, 1, value························· ' measure pulse input
··· DEBUG DEC value, CR
··· IF (value > 4000) THEN····················· ' evaluate duration
····· DEBUG "Value was greater than 4000"
··· IF (value = 4000) THEN
····· DEBUG "Value was equal to 4000"
····IF· (value < 4000) THEN
····· DEBUG "Value was less than 4000"
··· DEBUG CR, CR
··· PAUSE 1000
· LOOP
I re-read and re-read and I still don't get it unless it is just a matter of good code writing. Thanks!
Post Edited (lightsout) : 3/19/2005 10:00:50 PM GMT
Comments
To get to your question, though, it's a matter of style.· In this case you code is dealing with a single variable, so it makes sense to keep the logic in a single structure.· Another solution to this problem is:
· SELECT value
··· CASE >4000
····· DEBUG "Value was greater than 4000"
··· CASE 4000
····· DEBUG "Value equal to 4000"
··· CASE ELSE
····· DEBUG "Value less than 4000"
· ENDSELECT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
Your answer also brings the question,·Will all of my programs I have worked on in 2.0 work fine in 2.5 ??? Like if I copy & paste ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
GOTO Loop
'LOOP' is a 2.5 keyword. Other than that, you'll have no problems
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
·· Good point!· I wondered though (Since I haven't tried it), would specifying the 2.0 directive allow those types of things in the new software?· I suppose I could try it...But then what would be the point?·
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com