Using o-words with PlanetCNC TNG software: Conditional statements

You can use o-word conditional statements with PlanetCNC TNG.

O-word conditional statement consist of  if, elseif, else and endif keywords.

All keywords of the same conditional statement should use same o-word number.

Example of if…endif conditional statement:

%
#1=10
o100 if [#1 EQ 10]
 (PRINT,Condition is true)
o100 endif
%

Parameter #1 is assigned value 10. o100 if statement checks if parameter #1 equals (EQ) value 10. Because condition is true, program executes print command that is included in this conditional statement. o100 if statement is ended with o100 endif.

This code will display in Log:

Example of if, else…endif conditional statement:

%
#1=10
o100 if [#1 EQ 9]
(PRINT,10 equals 9)
o100 else
(PRINT,10 does not equal 9)
o100 endif
%

Paramter #1 is assigned value 1o. o100 if statement checks if parameter #1 equals (EQ) value 9. Because condition is not true, program jumps to o100 else statement and executes print command unconditionally.

This code will display in Log:

 

Example of if, elseif…endif conditional statement:

%
 #1=10
 o100 if [#1 GT 20]
 (PRINT,10 is greater than 20)
 o100 elseif [#1 LT 20]
 (PRINT,10 is less than 20)
 o100 endif
 %

Paramter #1 is assigned value 1o. o100 if statement checks if parameter #1 is greater  than (GT) value 20. Because condition is not true program jumps to o100 elseif statement where its checked if parameter #1 is less then (LT) value 20. Because condition is true, program executes print command that is included in o100 elseif conditional statement. Also note how if, elseif and endif keywords use same o-word number.

This code will display in Log: