Adobe Scan 23 Mar 2023
Adobe Scan 23 Mar 2023
9 Statements
LEARNING OBJECTIVES
SNAP RECAP
You will learn aboul:
1. What is QB64? character set, constants and variables in
of
the different components QB64
2. What are
commands?
Introduction languages
French, etc., programming
such as English,
Similar to ordinary languages In fact, the application
of these rules
grammar and spelling.
also have rules of syntax, to be explicit, as it
stricter. This is
because a program has
is
in a programming language
the actions to be taken.
is a precise s t a t e m e n t of
written in QBASIC programming
which is used to compile programs
QB64 is an IDE consist of
language, the elements of QB64
other programming
language. Just like any the operators, and the statements. Let us
the variables,
the character set, the constants,
study about of these elements here.
some
Character Set
charactersand symbols. These can be digits,
QB64 commands are written using some
108
Constants
such
hValues thatva
do not change during the execution of the
program.
Constant are
following types.
C o n s t a n
c a n
t s
of the
be
t of
T h e s e
NumericC o n s t a n t s C o n s t a n t s
NumericC
numeric
meric digit
digits, that is, integers or real numbers, and can either be positive
the
a r e
o rnegative.
special
character.
ial charact example, 1234, 0.75, 11.45, -18, etc. are all valid
For
include any
whereas 56!, 2/3, OE3, "764", etc. are invalid numeric constants.
ncluic
numeric
c o n s t a n t s
S t r i n g C o n s t a n t s
Variables
named memory
location FACT FILE
a variable is a
In QB64. which may or may
not change
a value
that contains A variable The reserved word in
the e x e c u t i o n
of the program. is a
during a time.
However, a programming language
o n e value at fixed meaning
can hold only word and can word which has
cannot be a reserved
variable n a m e variable name known to programming
of 40 characters. A
have a maximum have language and cannot be
with a letter and can
should always begin no space. redefined by the programmer.
decimal point but with
letters, numbers,
These are:
Variables are of two types.
109
String Variable
It is used for
storing string values (character set within double quotes). The string
variables can be named
using letter and numeric digits followed by a 's sign. These
always start with a letter. A few examples are given below:
Valid String Variable Invalid String Variable
Var$ "Name" %GSV$ =""Name"
V56S="Name" G%S="Name"
ACTIVITY
PRINT Statement
PRINT statement is used for displaying a value, message or an output on the monitor.
There are various ways in which a PRINT statement can be used in
QB64.
PRINT
PRINT statement without anything is used to display a blank line. For
example, the
and the corresponding output to display a blank line is given in figures 9.1 and 9.2.
input
PRINT "text/message"
This statement prints a text/message on the monitor. The text should be
enclosed within
double quotes ( "). For example, the input and the
corresponding output to display
Hello World' is given in figures 9.1 and 9.2,
respectively.
PRINT <any number>
This statement prints a number. If a number is to be displayed, quotations are not
used. For example, the input and the corresponding output to display 10' is given in
figures 9.l and 9.2, respectively.
110
PRINT with Separators
Help
UiewSearch Run 0ptions he roll nher of lex
Tile 4It Untitledm
of olox (
on)is 1M
Thie he ght
APRNELLO
PRINT HELLO
is
3ERI
4PRINTThe roll nunber of Aiex
Cin cn)ii"
134
of nlex
sitNT Te
Jeight
Status
ooNS A toEO
various PRINT
9.2 Output
sereen for
PRINNT
Fig.
statements
various
Input
screenfor
Fig. 9.1 s t a t e m e n t s
prints c o m m a
This sta
s t a t e m e n t
separated
by a
are
be d i s p l a y e d
from number.
ACTIVITY
that:
and height.
your age
p r o g r a m
Write a
small
name,
skips
s kips
school address
and your city.
command
nmands to print your
difference in
your
to see the
1.
1. Pri
Prints
PRINT with commas or vice versa
multiple semicolons
r
enlace
e p l a c e
Use
then
and
Run
it
3 t h e o u t p u t .
GLOSSARY
Character set It is a set of characters and symbols based on which QB64 commands are
written.
Constant It is a value that does not change during the execution of a program.
INPUT statement It is a statement used for accepting a value (text or numbers) from the
user at the time of program execution.
LET statement It is a statement uscd for assigning a value to a variable within a program
whose value may change during the execution of the p gram.
monitor
program.
lt stands for remark and it adds
comments in a
REM
program execution.
a space of one
114
EXERCISE
Tou
statement.
(text or
numbers) from the
2. Print is a name of the memory location.
variable within a
of the gram. program 3. Variables are non-executable statements.
a blank line. 3. To
Pd
assign a value 10 to
number variable N2.
a
| leave a
space of one 4. To
L Le
assign a string value "ABC" to a
string variable NAME2.
ne space in between. 5. To give comments THIS IS A
SAMPLE PROGRAM.
e the readability of a 6. To
accept class teacher's name in Le AB
the variable
D. Answer the following
questions.
CLTEACHER. Kem sasip
1. What is a PRINT statement?
Give two
tw examples.
2. What is a variable?
Explain two types of
3. What is the use of REM variables.
4. What is the importa
statement? Give an
rtance of the
INPUT example.
5. What is the use of LET
statement? Give statement? Give an
a
small code to
example.
supp
upport yQur
LAB WORK
program
for the following:
Write a
welcome message as
the variables and display a
of two friends in
Accept the
name
end nne, f/3
shown here.
<name2>
end n ard
l> and" anaa
Hi < n a m e Cde
Welcome to my party
PROJECT WORK
of five questions
enter the answer
to
by the
user.
will ask the
user
answers given
program
where you using the them at
Design a quiz friendly
messages
and use
the user
questions
Display of
different
entered by you.
five
answers
variable to input
five a quiz.
Hint:
create
it look ike
to make
places
appropriate
WHOAMI? Hungary.
I
Budapest,
1926 in
on 31 May 1940.
born States in
I was
United
along
with
to the language learn
migrated new to
completely beginners
a for of
enough kinds
developed
I Kurtz,
simple
handle
different
Thomas
E. to
enough
flexible
yet
I n s t r u c t i o n
quickly,
Symbolic
a p p l i c a t i o n s . All-purpose
Beginner's BASIC.
was
the known
as
**********
This commonly *******************
more
***
Code, *****
******
I am...ooooopgo