Hi,
There are basically two formats for the IF command:
1. IF
<conditional test> THEN
GOTO <a label in another part of the Program>
2. IF
<conditional test> THEN
: <do other things> : ENDIF
One problem is that PICaxe Basic is a little "Relaxed" about the syntax, which arguably is not a good idea for an "educational" environment. The reason is presumably to avoid discouraging students with an excessive number of pedantic "Syntax Error" reports.
The GOTO in the first version is "optional", but you might notice that I added it to the first line of the code that I gave in your
other thread. Since this command sends the program flow "somewhere else" (conditionally) , then the instruction has obviously "finished", so no END {IF} is required.
Note the colons (
: ) in the second format. They represent a "new line", which allows the program to be written in a more compact form, but again the PE/Compiler sometimes considers them "Optional" when it can "guess" what was intended. Looking back at that other post, I really should have also "corrected" the PWM lines as: if b1 =< b3 then
: pwmout C.2, 199,0
: endif (note the colons), or better still, written it as three lines with the pwm line indented.
In the second version of the
IF command, there can be any number of subsequent (conditional) expressions (in multiple lines or separated by colons), so the Editor/Compiler cannot "guess" when they have finished, so the
ENDIF is mandatory.
Cheers, Alan.