User Manual
MCP Series
Brushed DC Motor Controllers
MCP Series User Manual
166
Advanced Arguments
Now that we have covered the basics of the IF..THEN commands we can explore optional syntax.
The next section will explain each with sample code that will display the result so you can follow
along.
ENDIF Example
In some cases you may want to run a block of code when the condition is true. MCL can execute
a command or commands directly after a THEN statement, instead of jumping to a label. The
ENDIF is used to tell MCL run the following commands after THEN if the condition is true. So
ENDIF literately mean what it says, lets end the IF. When the IF..THEN condition is false ENDIF
tells MBasic to instead, run the commands after ENDIF. This simply resumes normal program
operation. ENDIF is an easy way to execute a group of commands based on some condition
returning true or completely skipping them if the condition is false.
value var long
value = 0
main
value = value+1
if value = 10 then
value = 0
endif
;display the value on the PC terminal window
puts 0,["Value=",dec value,13]
pause 1000
goto main
ELSEIF Example
In some cases you may want to test for several possible conditions. ELSEIF allows you to check
multiple possible conditions until one of them is true using a single IF..ENDIF block. Until one of
the ELSEIF conditions is found to be true each condition will be tested. As soon as one is found
to be true, the code in that section will execute and the program execution will continue starting
after the ENDIF.
if temp = 10 then
temp = 20
elseif temp = 20
temp = 10
endif