CT8(Q4)ControlStructure
CT8(Q4)ControlStructure
Creative Technologies 8
Quarter 4 | Control Structure
– IId-m-3.1)
Objectives
programming;
Let’s Understand
When a program is running, the code is being read by the computer line by
line (from top to bottom, and for the most part left to right), just like you would
read a book. This is known as the “code flow“, now as the code is being read from
top to bottom, it may hit a point where it needs to make a decision, this decision
could make the code jump to a completely different part of the program, or it could
make it re-run a certain piece again, or just plain skip a bunch of code. You could
think of this process like if you were to read and choose your own adventure book, you
get to page 4 of the book, and it says “if you want to do X, turn to page 14, if you want
to do Y, turn to page 5″. That decision that must be made by the reader is the
same decision that the computer program must make, only the computer program
has a strict set of rules to decide which direction to go (whereas if you were
book). So, this decision that must be made, that will in turn effect the flow of code,
term flow control details the direction the program takes (which way program control
control determines how a computer will respond when given certain conditions and
parameters.
• Repetition - used for looping, i.e., repeating a piece of code multiple times.
1. Sequential
logic has broken in any one of the lines, then the complete source code
The selection statement allows a program to test several conditions and execute
• Simple if
• if-else
• nested if
• if-elif-else
check.
if-else: The if-else statement evaluates the condition and will execute the body of if if
block of statements.
3. Repetition
instructions.
• for loop
• while loop
dictionary.
while loop: In Python, while loops are used to execute a block of statements
repeatedly until a given condition is satisfied. Then, the expression is checked again
and, if it is still true, the body is executed again. This continues until the expression
becomes false.
Let’s Apply
Structures and write the codes given in the example and save it with the
corresponding filename below. Submit the three programs in the Google Classroom.
Link: https://www.youtube.com/watch?v=kIPpTYjareA
1. Filename: classnumber_sequential
2. Filename: classnumber_selection
3. Filename: classnumber_repetition
Let’s Analyze
Direction: Write the following codes in Python and save according to its
corresponding filename. Run the code and take a screenshot of the output.
1. Filename: classnumber_py1
2. Filename: classnumber_py2
3. Filename: classnumber_py3
4. Filename: classnumber_py4
5. Filename: classnumber_py5
Direction: Read the questions carefully and select the letter of the
1. Which control structure will execute an instruction only after the computer
b. sequence d. function
a. If/else
b. While
c. do while
d. for
4. A grocery store manager wants a program that allows the clerk to enter original
price of an item and discount rate. The program then should display both the
a. Selection
b. Iteration
c. Sequence
5. Jackson has written a section of code in his program that instructs a character to
b. sequence d. function
Let’s Create
Direction: Write the codes for the following program. Submit your
1. Create a program that accepts two inputs of weight from the user and prints
2. Create a program that accept an integer grade from the user. If the grade is
below 83, then it should display the message in the screen “You did not meet
the grade requirement”. If the grade is greater than 83, then it should display
classnumber_create2.
References:
https://www.coderscampus.com/the-5-basic-concepts-of-any-programming-language-
concept-2/
https://www.kidscodecs.com/programming-control-flows/
https://www.educative.io/edpresso/what-are-control-flow-statements-in-python