EasyManua.ls Logo

Commodore VIC-20 - Page 39

Commodore VIC-20
308 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...
execution
continues
with
the
next
line
number
in
the
program.
A
true
result
makes
the
program
either
branch
to
the
line
number
after
the
word
THEN
or
execute
whatever
other
BASIC
statements
are
found
on
that
line.
EXAMPLE
1:
100
INPUT "TYPE
A
NUMBER1';
N
110
IF
N
<=
OTHEN
200
120
PRINT
"SQUARE
ROOT-"
SQR(N)
130
GOTO
100
200
PRINT
"NUMBER
MUST
BE
>0"
210
GOTO
100
This
program
prints
out
the
square
root of
any
positive
number.
The
IF
statement
here
is
used
to
validate
the
result
of
the
INPUT.
When
the
result
o(
N
<
-
0
is
true,
the
program
skips
to
line
200,
and
when
the
result
is
false
the
next
line
to
be
executed
is
120.
Note
that
GOTO
is
not
needed
with
IF
...
THEN,
as
in
line
110
where
THEN
200
actually
means
THEN
GOTO
200.
EXAMPLE
2:
100
FOR
L
=
1
TO
100
110
IF
RND(1}
<
.5
THEN
X
- X +
1
:
GOTO
130
120
Y
= Y
+
1
130
NEXT
L
140
PRINT
"HEADS-
"
X
150
PRINT
"TAILS
=
"
Y
The
IF
in
line
120
tests
a
random number
to
see
if
it
is
less
than
.5.
When
the
result
is
true,
the
whole
series
of
statements
following
the
word
THEN
is
executed:
first
X
is
incremented
by
1,
then
the
program
skips
to
line
130.
When
the
result
is
false,
the
program
drops
to
the
next
statement,
line
120.
EXAMPLE
3:
100
PRINT
CHRS(147);
110
FOR
X
=
1
TO
23
120
FOR
Y
-
1
TO
22
130
IFX
=
23ANDY
=
22THENPRINTCHR$(157)CHR$(148);
140
PRINT
"Z";
150
NEXT:NEXT
160
GOTO
160
23

Other manuals for Commodore VIC-20

Related product manuals