Programming Languages (Css 2) : Number of Sessions (Time Allotment) : 60 Hours (2nd Quarter)
Programming Languages (Css 2) : Number of Sessions (Time Allotment) : 60 Hours (2nd Quarter)
LOGIC FORMULATION
SUMMARY OF LEARNING OUTCOMES (LO):
➢ LO 01: Conditional Statements
➢ LO 02: Looping Constructs
TANAUAN INSTITUTE, INC.
Senior High School Department
Modified Learning Scheme: Workbook
PROGRAMMING LANGUAGES (CSS 2)
1st Semester, S.Y. 2020-2021
Subject Teacher: LORIE A. AVILLANOZA
Values Integration:
Nowadays, PROGRAMMING is already a large part of daily life-from games in gadgets to mainstream movies,
they are anywhere, However, a few decades ago, program is very limited. Programming came a long way before
getting to gadgets, televisions and big screens. Explain problem definition, problem analysis, algorithm, and
coding and debugging.
• Identify and explain conditions and Boolean value
• Enumerate and discuss the logical operators
Questions
1. What are the Importance of CONDITIONAL STATEMENTS?
3. What are some rules that you think must be followed when creating a LOGICAL
OPERATORS?
Discussion :
Conditions are statements that result in a Boolean value. A Boolean value may either be TRUE or
FALSE. Conditions are logical expressions. Logical expressions evaluate to a Boolean value. There are
two types of operators which provide Boolean values as results – logical and relational.
Logical Operators are mainly used to control program flow. They are usually part of an IF, WHILE, or
some other control statements. Logical operators allow a program to make a decision based on multiple
conditions.
Relational Operators are used to compare two operands and determine the validity of a relationship.
Conditions:
✓ are statements that result to a Boolean value.
Boolean value
✓ may either be a TRUE or FALSE, 0 or 1 value
✓ Operators which give Boolean value as results:
- Relational Operators
- Logical Operators
AND OR
NOT
The NOT truth table shows the nature of the NOT operator. A truth table is a type of mathematical table
used in logic to determine whether an expression is true or valid. Such a table typically contains several
rows and columns with the top row representing the logical variables and combinations, in increasing
complexity leading up to the final function.
Basically, the NOT operator operates on a single value and the result is the reverse of the operand
Boolean value. Therefore, a TRUE will become FALSE and a FALSE will become TRUE. Note that in
flowcharting, TRUE may be represented by T or 1 and FALSE may be represented by F or 0.
CONDITIONAL STATEMENTS
• NOT operator
• reverses the logic or result of a certain condition
Condition A !A
F T
T F
The AND and OR operators are commonly used operators in conditions. The AND operator is used if
you want a strict condition. For AND to result to TRUE, both conditions must be satisfied. The OR
operator is used when either one of the conditions is true.
The truth table shows how the AND and OR operators function. For the AND operator, the result will
become TRUE if and only if both conditions are TRUE, while the OR operator becomes TRUE if either
one or both conditions are TRUE.
F F F F
F T F T
T F F T
T T T T
Relational Operators
Compare two values and return a Boolean value depending on whether the test condition is true or false.
• Compare two values and returns a Boolean value depending on whether the test condition is true or
false.
It has been discussed previously that that a diamond box is used for decision making within a flowchart.
It should be noted that what you place inside the diamond box are conditions – conditions that either
result to TRUE or FALSE.
Also, you don’t place conditions that are in essay form. You must be able to represent it in a
mathematical form.
T F
T F
The Dual Alternative Selection Structure allows you to perform two different tasks depending on the
result of the condition’s evaluation.
One path is performed if the evaluation resulted to TRUE and the other if it is FALSE.
No Yes
x == 2? Disp “Hi”
Stop
No Yes
Disp “Bye”
x == 3?
Disp “Invalid”
Solution #1:
Get Dept
Yes
Dept< = 3? Disp “Mr. X”
No Yes
No
Disp “Mr. Z”
ACTIVITY 1:
Directions: Draw a flowchart that will ask the user to enter a character (either ‘M’ or ‘F’) to indicate the user’s
gender (Male or Female).
• Display “Male” if the user enters the value of ‘M’ and “Female” for the value of ‘F’
• Assume all inputs are correct
ACTIVITY 2:
Directions: Draw a flowchart that will ask the user to input the values of four variables, A, B, C, and D
• Print “TRUE” if A is greater than B, and C is less than D or if A is greater than B and C is less than D
• Print “FALSE” if otherwise.
A loop can be executed and/or stopped. Running and stopping the loop is dependent on the condition. If
you want the loop to run, the condition must be TRUE. If you want the loop to stop, the condition must
be FALSE. The condition for it to become TRUE or FALSE must be dependent on a variable.
For instance, 5 < 8 will always be TRUE; however, using x < 8 the result will be dependent on the value
of x. In programming, the value of the variable can be changed in three basic ways:
1. Through mathematical computations (ex: Set x to x +
3 or Increment x by 3)
2. user input (enter x)
3. by initialization or passing of values (ex: x = 4, y = x)
Yes
X>Y? Process A
No
The repetition structure, also referred to as a loop or iteration, is a type of structure that repeats one or
more instructions until a certain condition is met.
There are various ways of setting up a loop depending on the needs of the program. The action
performed by a repetition structure must eventually cause the loop to terminate. Otherwise, an infinite
loop is created.
Take note of the use of the diamond symbol. One possible loop can test a condition, perform an action if
the condition is satisfied, and then test the condition again. The action is repeated as long as the
condition is satisfied.
Looping Constructs
In the flowchart segment in the slide, the question “is X < Y?” is asked. If the answer is yes, then
Process A is performed and the question is asked again. Process A is repeated as long as X is less than
Y. When X is no longer less than Y, the repetition stops and the structure is exited.
Yes
X < Y? Display X
No
Yes
X < Y? Display X X=X+1
No
a pre-test repetition structure where the condition is tested BEFORE any actions are performed.
In this structure, if the condition does not exist, the loop will never begin and the actions inside the
loop will not be executed.
Display X
X=X+1
Yes
X < Y?
No
This flowchart segment shows a post-test repetition structure wherein the condition is tested AFTER the
actions are performed. This type of structure always performs its actions at least once.
Output: X=5
5
4
3 Yes
2 X> Disp X
1
No 0?
DONE
Stop
X, Y
Get X, Y
Yes
X<Y X=X+1
No
Disp X
Disp “Done”
Stop
Start
Gen=“”
Ctr=1
No
Disp Ctr<=5
‘Invalid’
Yes
Stop
Get Gen
Yes
Gen!=‘M’
AND
Gen!=‘F’
No
Yes No
Gen==‘M’
Ctr=Ctr+1
ACTIVITY 1: Flowcharting
At the end of this exercise the students are expected to:
• Create a flowchart based on the given problem.
Materials:
Flash Drive
Note: Save all your flowcharts in your flash disk. Use appropriate file names for each
flowchart drawing.
Directions: Create the flowchart of the following problems:
1. Display the user’s name, birthday, age, gender, and phone number.
The flowchart should display the variables with the following format:
Name: ??????
Age: ??
Birthday: mm/dd/yyyy
Gender: ?
Phone#: ???????
ACTIVITY 2: Flowcharting
Directions: Create a flowchart that displays the student’s average score for three quizzes.
• Assume that there are 3 sections each having 5 students.
• The only valid number to be entered is 1 – 100 for the quizzes.
• Should the user enter an invalid number, display an appropriate error message and ask the user reenter
a value for the 3 quizzes.
References :
• Hoffer J., George G., & Valacich J. (2008). In 5 Ed., Modern systems
analysis and design. Pearson Prentice Hall.