Prog 1 Q2 Mod 2 WK 34
Prog 1 Q2 Mod 2 WK 34
Prog 1 Q2 Mod 2 WK 34
Programming 1
Grade 9 – Special Science Program
Quarter 2 Module 2 Week 3&4
Elements of Small Basic Program
Programming 1 – Grade 9 (Special Science Program)
Alternative Delivery Mode
Module Writer: Noli A. Esmeña
Quarter 2 – Module 2, Week 3&4: Elements of Small Basic Program
First Edition, 2020
Republic Act 8293, section 176 states that: No copyright shall subsist in any work
of the Government of the Philippines. However, prior approval of the government agency or
office wherein the work is created shall be necessary for the exploitation of such work for a
profit. Such agency or office may, among other things, impose as a condition the payment of
royalties.
Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand names,
trademarks, etc.) included in this module are owned by their respective copyright holders.
Every effort has been exerted to locate and seek permission to use these materials from their
respective copyright owners. The publisher and authors do not represent nor claim
ownership over them.
1. Use the module with care. Do not put unnecessary mark/s on any part of the
module. Use a separate sheet of paper in answering the exercises.
2. Don’t forget to answer What I Know before moving on to the other activities included
in the module.
3. Read the instruction carefully before doing each task.
4. Observe honesty and integrity in doing the tasks and checking your answers.
5. Finish the task at hand before proceeding to the next.
6. If you encounter any difficulty in answering the tasks in this module, do not hesitate
to consult your teacher or facilitator. Always bear in mind that you are not alone. We
hope that through this material, you will experience meaningful learning and gain a
deep understanding of the relevant competencies. You can do it!
This module will show you the elements of a small basic program which will help you
revisit your knowledge on what makes a real computer program.
The module consists of two (2) lessons, namely:
• Lesson 1 – Introducing Variables in Small Basic
• Lesson 2 – Operators and Control Structures of Small Basic
After going through this module, you are expected to:
1. define variables
2. distinguish the use of variables in program statements
3. determine the rules in naming variables
4. explain the meaning of the relational and logical operators
5. define control structure
6. distinguish between the types of control structure
7. determine the needed input and output for simple programming problems
8. use variables, numbers, characters, constants, operators, commas, and
semicolons correctly in programs
2
What I Know
Multiple Choice
Directions: Before you study this module, answer this to test your existing knowledge.
Write the capital letter of your chosen answer on a separate sheet of paper.
3
Lesson 1 Introducing Variables in Small Basic
You have learned about variables in the previous quarter, but how big is the role
that it is playing in a computer program? To answer this question, you will need to
experience how it is being used in an actual program, in this case, the small basic
program. Let’s begin!
What’s In
Activity 1. 3W Table
Directions: Copy the table below on your paper, then answer it with the required
data. On the first column, list everything you know about variables (do not browse
the internet). In the second column, list everything you want to know about
variables. The third column will be answered after studying this lesson.
Enumerate what you know Enumerate what you want to Enumerate what you have
about variables here know about variables here learned about variables here
What’s New
What is It
Wouldn’t it be nice if our program can say “Hello” with the user's name instead of
saying the generic “Hello World?” To do that we must first ask the user for his/her
name and then store it somewhere and then print out “Hello” with the user’s name.
Let’s see how we can do that.
4
Enter the following program in your small basic program editor:
TextWindow.Write("Enter your Name: ")
name = TextWindow.Read()
TextWindow.WriteLine("Hello " + name)
When you type and execute this program, you’ll see an output like in Figure 1.
Go back to the 3W table you have filled out at the beginning of this lesson and fill
out the third column with everything you have learned about variables.
What I Know What I Want To Know What I Have Learned
About Variables
Enumerate what you know Enumerate what you want to Enumerate what you have
about variables here know about variables here learned about variables here
6
Lesson 2 Operators & Control Structures of Small Basic
Variables are not just the essential elements of a program. Sometimes, operators and
structures are needed to solve the programming problem. In this lesson, you will be
introduced to how they are used in a real small basic program. Let’s start!
What’s In
Activity 4. Identification
Some of the essential terms that will be used in this lesson are inside the box below.
Those terms were tackled in the previous quarter. Choose the correct answer from
the box. Write your answer on your paper. This will be checked but not recorded.
Answer honestly without the help of the internet.
Relational Arithmetic Logical Sequential Selection Repetition
Operators Operators Operators Structure Structure Structure
What’s New
Operators are commonly used in Mathematics and Science. They are used to
indicate an operation between different symbols such as digits or letters. The
operators dictate what operation will be applied. In programming, these operators
are also used to apply operations on inputs either from the user or from the
programmer itself. Aside from operators, structures are also very important because
they dictate the flow of the program. Let’s begin learning more about them.
What is It
Congratulations! You have now successfully used operators in small basic. On what
part?
Arithmetic, Comparison, and Logical Operators
By typing the conversion formula, you have used multiplication (*), division (/), and
subtraction (-). The other operator not used, is the addition (+). These operators are
called arithmetic operators. You can also perform other mathematical operations by
using the “Math” object and its set of operations such as remainder and square root.
The other operators are relational or comparison operators and logical operators
which will be used in the next module. Comparison operators can be used in
conditions for If, While, and For statements. Logical (Boolean) operators can be used
in conditions for If and While statements.
Operator Symbol
= (equal to)*
< (less than)
> (greater than)
Comparison Operators
<= (less than or equal to)
>= (greater than or equal to)
<> (not equal to)
And
Logical Operators
Or
*Only equal (=) operator can compare two texts or two numbers. Other operators are for
numbers only.
https://tinyurl.com/yb4bjypt
Control Structures
8
Control Structures specify the flow of control in programs. They are also called
logic. It analyzes and chooses in which direction a program flows based on certain
parameters or conditions (https://tinyurl.com/yda72zhy).
There are three basic types of control structures used in programming.
1. Sequential Structure. Sequence control refers to the linear execution of codes
within a program. In sequence control, the statements are executed one by
one in consecutive order.
2. Selection Structure. Selection control enables the programmer to assign
different events for different situations. Before it takes the next step, it asks a
question. An example is the “If…Then…Else” statement.
3. Repetition Structure/Loops. Repetition structure or loops are used when a
program needs to repeatedly process one or more instructions until some
condition is met at which time the loop ends.
You will be applying the selection and repetition structure on the next module.
9
What’s More
10