You are on page 1of 22

Chapter 10-

QB64
Programming
Statements
Intro
QB64 helps us to work with several commands using various operators and
looping statements. These commands help us to write programs to solve various
complex problem.

The set of instructions written in a specific programming language is


called as programming statements.

There are 3 types of programming statements:

Sequential Conditional Iteration


Sequential Statements

Sequential statements are executed one after


the other in the sequence they are written.

Written first are executed first.


Conditional Statements
When the flow of control of the program is based on a
condition then you make use of the conditional
statements.
Operators

Operators are the symbols used for evaluating an


expression in a language. The following are the categories of
operators used in QB64 language.

Arithmetic Operators Relational Operators

Logical Operators String Operators


Arithmetic Operators
These are used for evaluating a mathematical expression in a programming
statement.

Action Operator Example


Add + PRINT 6+5
Subtract - PRINT 9-2
Multiply * PRINT 4*6
Divide / PRINT 10/2
Exponential ^ PRINT 4^2
Modulus MOD PRINT 10 MOD 2
Integer Division \ PRINT 15\2
Challenge!

6 Find the area of the square

14
Find the area of the rectangle
32
IF THEN ELSE Statement

IF command is used for executing a statement based on a


condition. It implements the branching of the execution in two
parts:

1.If the condition written next to IF is true, then the statement


part will be executed.
2.If the condition is false, then the statement after the ELSE
part will be executed.
IF THEN ELSE Statement
There are 2 types of syntax when writing conditional
programming structure in Qbasic.
Syntax/Rules when using IF THEN ELSE Statement
IF condition THEN True_Statement ELSE False_Statement

IF condition THEN
True_Statement
ELSE
False_Statement
END IF
Relational Operators
These set of operators are used when you want to make a comparison between
any two values. It displays the result as true or false depending upon the value
given.

Action Operator
Less than <
Less than or equal to =< OR <=
Greater than >
Greater than or equal to >= OR =>
Equal to =
Not equal to <> OR ><
Challenge
Create a program to accept the age of the user, if the user age
bigger than 17 then display text “You are allowed to join the
driving test” otherwise/else “You are not allowed”
Challenge
Create a program to accept a number from the user.
If the number entered is bigger than 0 then it will display “This is
a positive number”, otherwise it will display “This is a negative
number”.
Challenge
Create a program to accept a number from the user.
If the number entered is an even number then it will display “This
is an even number”, otherwise it will display “This is an odd
number”.
Logical Operators
These are used for combining two or more conditions. These operators give a
single value, which is either true or false.

Action Operator
All condition should be true AND
Any one condition should be true OR
Negates the condition NOT
Example
Create a program to accept the age of the user. Let’s make an
example that only people who are older than 17 and not older
than 21 able to join the driving test.
Example
Create a program to accept the age of the user and a question
“Do you have an ID?”, if the user insert their age bigger than 17
or they have an ID then they are allowed to join the test
otherwise/else they are not allowed.
Example
Somehow if the age of the user is 20 they are not allowed to join
the test. We can use NOT operator here.
String Operators
Also called as concatenation operators. These ae used to combine 2 strings
together.

Example:
Pring “have a”+”nice day”
ELSEIF Statement
The ELSEIF statement allows you to execute a set of statements
if the previous condition is false. It is generally used when you
have multiple conditions in a program.
IF condition THEN
Statement
ELSEIF condition THEN
Statement
ELSEIF condition THEN
Statement
ELSE
Statement
END IF
Example
Create a program to accept the color of traffic light.
If the color entered is red, then it will display “You need to stop”
If the color entered is yellow, then it will display “You need to wait”
If the color entered is green, then it will display “ You can go”
Challenge!
Write a QB64 program to accept any city from the user and display
landmark of that city.
Example:
City Landmark
Jakarta Monas

Create at least 10 different cities and their landmarks. (Google the


information if you need).

See the answer on next page.

You might also like