EasyManua.ls Logo

Commodore 128D - Page 267

Commodore 128D
427 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
DO/LOOP/WHILE/
UNTIL/EXIT
—Define
and
control
a
program
loop
DO
[UNTIL
condition
|
WHILE
condition]
statements
[EXIT]
LOOP
[UNTIL
condition
|
WHILE
condition]
This
loop
structure
performs
the
statements
between
the
DO
state
ment
and
the
LOOP
statement.
If
no
UNTIL
or
WHILE
modifies
either
the
DO
or
the
LOOP
statement,
execution
of
the
statements
in
between
continues
indefinitely.
If
an
EXIT
statement
is
encountered
in
the
body
of
a
DO
loop,
execution
is
transferred
to
the
first
state
ment
following
the
LOOP
statement.
DO
loops
may
be
nested,
follow
ing
the
rules
defined
by
the
FOR-NEXT
structure.
If
the
UNTIL
parameter
is
specified,
the
program
continues
looping
until
the
con
dition
is
satisfied
(becomes
true).
The
WHILE
parameter
is
basically
the
opposite
of
the
UNTIL
parameter:
the
program
continues
looping
as
long
as
the
condition
is
TRUE.
As
soon
as
the
condition
is
no
longer
true,
program
control
resumes
with
the
statement
immedi
ately
following
the
LOOP
statement.
An
example
of
a
condition
(bool
ean
argument)
is
A
=
1,
or
G>65.
EXAMPLE:
10X
=
25
20
DO
UNTIL
X
=
0
30X
=
X-1
40
PRINT
"X
=
";X
50
LOOP
This
example
performs
the
statements
X
=
X-1
and
PRINT
"X=";X
until
X
=
0.
When
X
=
0
the
program
resumes
with
the
PRINT
"End
of
Loop"
statement
immediately
following
LOOP.
60
PRINT
"END
OF
LOOP"
10
DO
WHILE
A$<>
CHR$
(13):GETKEY
A$:PRINT
A$:LOOP
20
PRINT
"THE
RETURN
KEY
HAS
BEEN
PRESSED"
This
DO
loop
waits
for
a
key
to
be
pressed,
receives
input
from
the
keyboard
one
character
at
a
time
and
prints
the
letter
of
the
key
which
was
pressed.
If
the
RETURN
key
was
pressed,
control
is
transferred
out
of
the
loop
and
line
20
is
executed.
10
DOPEN
#8,"SEQFILE"This
program
opens
file
"SEQFILE"
20
DO
30
GET
#8,A$
40
PRINT
A$;
50
LOOP
UNTIL
ST
60
DCLOSE
#8
and
gets
data
until
the
ST
system
variable
indicates
all
data
has
been
input
and
printed.
259
BASIC
7.0
ENCYCLOPEDIA—Basic
Commands
and
Statements

Table of Contents

Other manuals for Commodore 128D

Related product manuals