Control Structures: Creative Technology 3
Control Structures: Creative Technology 3
Creative Technology 3
Control Structures
Learning Competency:
Describe how control structures is used in programming.
SSP_TLE-CT8AP-IId-m-3.1
Try This!
Direction. Unscramble the following words with the help of the given clue.
WORD CLUE
POLO The purpose is to repeat a statement a certain number of times or while a condition
is fulfilled.
TCEELSNIO It is used to execute one or more statements if a condition is met.
OOLRTCL ERUTCURTS Commands that enable a program to take decisions, following one path or another
Figure A Figure B
Control Structure can be considered as the building blocks of computer programs. They are commands
that enable a program to “take decisions”, following one path or another. A program is usually not limited to a
linear sequence of instructions since during its process it may bifurcate, repeat code or bypass sections. Control
Structures are the blocks that analyze variables and choose directions in which to go based on given parame-
ters.
1. Sequence
The sequence structure directs the computer to process program instructions one after the another, in the
order listed in the program.
Example:
A. Binary selection. There are two possible choices to choose. Binary uses IF… ELSE... ENDIF. If the condition is met(true)
then one path is taken, otherwise (false) the other path is taken.
Example:
In this example, The value in the variable age is compared to the first “case”, which is the value 18 (also
called the listed value) using an equality comparison or is “age equal to 18”. If it is true, the message is assigned
the value “You can vote.” and the next line of code (the break) is done (which jumps us to the end of the con-
trol structure). If it is false, it moves on to the next case for comparison. The last item is referred to as the de-
fault. If the age is not equal to 18, 40 or 60 you get the default message “ Error”.
3. Repetition
The Repetition structure directs the computer to repeat one or more instructions until some condition is
met.
• It is also called loop or iteration.
• The loop is created to return the program to where the repetition has started as long as it takes until
the condition is met.
Types of loop:
1. While
2. Do-while
3. For loop
i = 0
n = 5
• When we perform the this statement , the value of i is
now equals to 1 (0 + 1 = 1).
Figure A Figure B
Figure E Figure F
,
Figure D
Reflect
After you performed the activity above,
1. Did you find difficulty in identifying the different control structures? Why or why not?
2. How does this activity help you understand the flow of instructions of each control structure?
For numbers 7-10, identify the parts of the loop structure labeled
A, B, C, D in Figure A.
Figure B.
FLOWCHART . It is a type of diagram that represents an algorithm, workflow or process. The flowchart shows
the steps as boxes of various kinds, and their order by connecting the boxes with arrows. This diagrammatic
representation illustrates a solution model to a given problem.
Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields.
Building blocks . Building blocks may refer to the components of a particular programming language. In
Java, one example component of a building blocks are statements. Statements are action or sequence of
actions, given as a command in code. A statement ends with a semi-colon (;). An example structure of Java is
shown below.
// statements