BASIC commands
PROGRAMMING MANUAL
97
Revi
si
on 3.0
3.2.150 IF..THEN..ELSE..ENDIF
/i
3.2.151 IN
/i
Type
Program control command
Syntax
IF condition_1 THEN commands {ELSEIF condition_i THEN commands}
[ ELSE commands ] ENDIF
IF condition_1 THEN commands
Description
This structure controls the flow of the program based on the results of the con-
dition. If the condition is
TRUE
the commands following
THEN
up to
ELSEIF
,
ELSE
or
ENDIF
is executed. If the condition is
FALSE
and the command of a
subsequent
ELSEIF
substructre is
TRUE
, the commands of this substructure
are executed. If all conditions are
FALSE
the commands following
ELSE
will
be executed or the program will resume at the line after
ENDIF
in case no
ELSE
is included. The
ENDIF
is used to mark the end of the conditional block.
Note:
IF..THEN..ELSE..ENDIF
sequences can be nested without limit. For a
multi-line
IF..THEN
construction, there must not be any statement after
THEN
.
A single-line construction must not use
ENDIF
.
Arguments
•
condition_i
A logical expression.
•
commands
One or more BASIC commands.
Example
IF MPOS > (0.22 * VR(0)) THEN GOTO exceeds_length
Example
IF IN(0) = ON THEN
count = count + 1
PRINT "COUNTS = ";count
fail = 0
ELSE
fail = fail + 1
ENDIF
Example
IF IN(stop)=ON THEN
OP(8,ON)
VR(cycle_flag)=0
ELSEIF IN(start_cycle)=ON THEN
VR(cycle_flag)=1
ELSEIF IN(step1)=ON THEN
VR(cycle_flag)=99
ENDIF
Example
IF key_char=$31 THEN
GOSUB char_1
ELSEIF key_char=$32 THEN
GOSUB char_2
ELSEIF key_char=$33 THEN
GOSUB char_3
ELSE
PRINT "Character unknown"
ENDIF
See also
N/A
Type
I/O function
Syntax
IN(input_number [ ,final_input_number ])
IN
Description
The
IN
function returns the value of digital inputs.
•
IN(input_number, final_input_number)
will return the binary sum of
the group of inputs. The two arguments must be less than 24 apart.
•
IN(input_number)
with the value for
input_number
less than 32 will
return the value of the particular channel.
•
IN
(without arguments) will return the binary sum of the first 24 inputs (as
IN(0,23)
).
Arguments
•
input_number
The number of the input for which to return a value. Value: An
integer between 0 and 31.
•
final_ input_number
The number of the last input for which to return a value. Value: An
integer between 0 and 31.
I52E-EN-03.book Seite 97 Freitag, 29. Juni 2007 11:55 11