IF¶
Function¶
IF selectively executes program statements dependent on result of an expression.
Syntax¶
IF A(op)B THEN C
Where A is an expression, variable or constant and (op) is an operator =, < , > etc. The operator may be logical or omitted. See section Logical Operators for further details.
B is an expression, variable or constant
C is either a line number or program statement.
Examples¶
IF A = B THEN 100
IF A>B THEN PRINT "NO"
C may be a multiple statement which will be entirely executed if the condition is true, but skipped if not.
HUNTER also permits nesting of IF statements.
Example:
IF A= B THEN IF C=D THEN PRINT "FINISHED":GOTO 1000
String expressions may be tested for equality or unequality, for example:
IF A$ + B$ = "ABCDEAB" THEN 100
or
IF A=B AND B=C OR D=5 THEN PRINT "TRUE"
In this example “TRUE” may be printed by one of two methods allowed by the OR operator as follows:
if A=B=C
if D=5
However,
IF A=B AND B=C AND D=5 THEN PRINT "TRUE"
will only print “TRUE” if all conditions are satisfied.
IF A THEN PRINT "TRUE"
will print “TRUE” only if the variable A is non-zero, i.e. if A=-19 then “TRUE” will be printed.
See Expressions And Operators and Logical Operators, for precise details of logical operators.
Remarks¶
For strings of unequal length the equality will be true if the string on the left of the equates is equal to or part of the string on the right as follows:
If A$ = “ABC” and B$ = “ABCD” then
A$ = B$ is true
B$ = A$ is not true