![QSI QTERM-R55 Скачать руководство пользователя страница 20](http://html1.mh-extra.com/html/qsi/qterm-r55/qterm-r55_user-manual_3304037020.webp)
10
QTERM-R55 User's Manual
QSI Corporation Fax 801-466-8792 Web www.qsicorp.com Phone 801-466-8770
2.5.1
The
if
Statement
The
if-then
statement is necessary for making deci-
sions. The syntax is as follows:
if [(]<condition>[)] then
<instructions>
[else
<alternative instructions>]
endif
As shown, the parentheses around <condition> are
optional. The
else
<alternative instructions> is also
optional. Note that
endif
can be written as
fi
.
<condition> is described below in Conditions (section
2.5.2). <instructions> and <alternative instructions> can be
be any series of BASIC statements. If <condition> evalu-
ates to TRUE, then <instructions> is executed. If <condi-
tion> evaluates to FALSE, <alternative instructions> (if
included) is executed.
2.5.2
Conditions
Numbers or arithmetic expressions can be compared with
the usual relational operators:
=
(equal),
<>
(not equal),
<
(less than),
<=
(less or equal),
>
(greater than) and
>=
(greater or equal).
Strings can be compared with the same set of operators,
where characters are ordered according to the ASCII char-
acter set. For example,
("a"<"b")
is true because
"a"
precedes
"b"
within the ASCII character set. Likewise
("a"="b")
is false.
More than one comparison can be combined with parenthe-
ses
()
and these keywords:
or
,
and
,
not
.
not
has higher
precedence than
and
, which in turn has higher precedence
than
or
(in the same way as
*
precedes
+
within arithmetic
expressions). This means that
not a>b or a==c and b>0
i
s the same as
((not a>b) or (a==c)) and (b>0)
Finally, the enclosing parentheses can be omitted, i.e.
if
a<10 then ...
is a valid statement.
2.5.3
Marking Locations in a Program
The first line in the Example 6 program (
label loop
) is
a
label
.
qaBASIC does not require line numbers, thus labels are
necessary to mark a specific location within your program
(however, see the following paragraph). You can compose
labels out of letters and digits. The keyword
label
is
required, and the label itself should be unique within your
program.
qaBASIC allows for line numbering. This feature makes
qaBASIC more compatible with traditional versions of
BASIC. Line numbers are just special types of labels with
the following properties:
•
Line numbers can appear only at the beginning of a
line.
•
Not every line needs a number and line numbers need
not be consecutive.
2.5.4
Jumping Around in a Program
A label by itself causes no special action. Only in conjunc-
tion with the
goto
statement (or
gosub
or
restore
)
does a label have any function. If qaBASIC encounters a
goto
statement (in the Example 6
goto loop
), then it
searches for the matching label (
label loop
) and pro-
ceeds to execute at the position of the label.
Note that you can even leave (and enter) a for-next loop
(see section 2.6) with goto.
Closely related to the
goto
command is the
gosub
com-
mand. If qaBASIC encounters a
gosub
statement, it
searches for the matching label (
label thanx
in Exam-
ple 6), and proceeds with execution at the position of the
label until it finds a
return
statement.
return
makes
qaBASIC return to the position of the original gosub and
proceed from there.
Note that both
goto
and
gosub
can be used as
on goto
and
on gosub
(see on gosub, on goto (section 2.5.5).
2.5.5
on gosub, on goto
The
on gosub
statement is followed by a list of labels
(
sorry,one,two,...
) in Example 9 (below). Depend-
ing on the value of the expression (
1
), the corre-
sponding label in the list is chosen: for example, if
1
evaluates to 3, the third label (
three
) is
selected and a
gosub
to this label is performed.
A
gosub
is always performed, regardless of the value of
the expression. More specifically, if
1
gives any-
thing less or equal to 1, then the first label (
sorry
) is cho-
sen. If
1
evaluates to anything greater or equal to
the number of elements in the list (which is 7 in Example
9), then the last label (
sorry
) is chosen. Therefore, the
Содержание QTERM-R55
Страница 4: ......
Страница 6: ...ii QTERM R55 User s Manual QSI Corporation Fax 801 466 8792 Web www qsicorp com Phone 801 466 8770...
Страница 10: ...vi QTERM User s Manual QSI Corporation Fax 801 466 8792 Web www qsicorp com Phone 801 466 8770...
Страница 14: ...4 QTERM R55 User s Manual QSI Corporation Fax 801 466 8792 Web www qsicorp com Phone 801 466 8770...
Страница 34: ...24 QTERM R55 User s Manual QSI Corporation Fax 801 466 8792 Web www qsicorp com Phone 801 466 8770...