0% found this document useful (0 votes)
3 views6 pages

Prog1Q3Mod4Wk6 7

This document is a teaching module for Programming 1, focusing on basic conditional statements in Pascal programming. It covers relational and Boolean operators, types of conditional statements, and provides examples and activities for students to apply their knowledge. The module includes practice questions, a summative test, and a performance task for students to demonstrate their understanding of conditional statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Prog1Q3Mod4Wk6 7

This document is a teaching module for Programming 1, focusing on basic conditional statements in Pascal programming. It covers relational and Boolean operators, types of conditional statements, and provides examples and activities for students to apply their knowledge. The module includes practice questions, a summative test, and a performance task for students to demonstrate their understanding of conditional statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Republic of the Philippines

Department of Education
Region 1
Pangasinan Division II

Programming 1, Quarter 3, Module 4, Week 6-7


Basic Conditional Statements in Pascal Programming
Name: _________________________________ Grade/Section: ___________________
Date: __________________________________

Objective: Apply the basic conditional statements in writing Pascal programs


Directions: Read the discussion then accomplish the activities that follow. Contact your subject
teacher for clarifications on the worksheet.
Introduction
On the previous worksheet, you applied basic
statements which mainly involved the use of variables and
arithmetic operators. In this worksheet, relational and Boolean
operators will be introduced. These operators will be used to
build what we call conditional statements. You have already
encountered these statements from the previous quarters.
Conditional statements are used in programs that involve
decision-making. Figure 1 illustrates the basic structure of
decision-making in most programming languages.

Figure 1. Decision-making structure in programming


https://www.tutorialspoint.com/pascal/images/decision_making.jpg

Relational and Boolean Operators


✓ Relational operators
Operator Description Examples

Checks if the values of two operands are equal, if yes, 5=5 is true
=
the condition becomes true. 5=6 is false
Checks if the values of two operands are not equal, if 5<>6 is true
<>
yes, then the condition becomes true. 5<>5 is false
Checks if the value of the left operand is greater than the
5>4 is true
> value of the right operand, if yes, then the condition
4>5 is false
becomes true.
Checks if the value of the left operand is less than the
4<5 is true
< value of the right operand, if yes, then the condition
5<4 is false
becomes true.
Checks if the value of the left operand is greater than or
5>=5 is true
>= equal to the value of the right operand, if yes, then the
5>=4 is true
condition becomes true.
Checks if the value of the left operand is less than or
5<=5 is true
<= equal to the value of the right operand, if yes, then the
5<=4 is false
condition becomes true.
Table 1. Relational operators in Pascal programming
Reference: https://www.tutorialspoint.com/pascal/pascal_operators.htm

Prepared: Noli A. Esmeña, Teacher I, Tayug NHS (2021) 1


✓ Basic Boolean operators
Operator Description Examples
If both operands are true, then the If (Science>=85) and
and
condition becomes true. (Math>=85) then (decision)*
If any of the two operands is true, then If (Height<165) or (Weight<60)
or
the condition becomes true. then (decision)*
Used to reverse the logical state of the
If not (password = 1234) then
not operand. If the condition is true, then the
(decision)*
logical not operator will make it false.
Table 2. Basic Boolean operators in Pascal programming
*See sample conditional statements to see the whole program
Reference: https://www.tutorialspoint.com/pascal/pascal_operators.htm

Types of Conditional Statements in Pascal


1. If - then statement – This is the simplest type of conditional statement. It consists of
a Boolean expression followed by one or more statements.
2. If-then-else statement – An if-then statement can be followed by an optional else
statement, which executes when the Boolean expression is false.
3. Nested if statements – You can use one if or else if statement inside
another if or else if statement(s).
4. Case statement – A case statement allows a variable to be tested for equality against
a list of values.
5. Case - else statement – It is similar to the if-then-else statement. Here, an else term
follows the case statement.
6. Nested case statements – You can use one case statement inside
another case statement(s).
Examples for if-then and if-then-else statements, the most basic conditional
statements, are given in the next part. To explore the rest of the conditional statements, you
may want to click this link:
https://www.tutorialspoint.com/pascal/pascal_decision_making.htm.

Example Conditional Statements


• Example 1: Application of relational operators (>=), logical AND operator, an if-then
statement.

Figure 2. Example Conditional Statement-1


• Code explanation
Example 1 shows a program that determines if the grades of a student in Science and
Math are qualified for the Special Science Program. At the beginning of the program, a
user will be asked to input the grades in Science and Math. After that, the conditional
statement that follows states that if the student’s grades in Science AND Math are greater
than or equal to (>=) 85 then the student is qualified for the Special Science Program. The
logical AND operator requires the student to meet two conditions (passing grade in
Science and Math). If one of the two subjects is not greater than or equal to 85 then the
qualifying message will not be displayed.

Prepared: Noli A. Esmeña, Teacher I, Tayug NHS (2021) 2


• Example 2: Application of less than relational operator (<), logical OR operator, and if-
then-else statement.

Figure 3. Example Conditional Statement-2


• Code explanation
Example 2 shows a program that determines if an applicant passed or failed a
physical examination based on his/her height and weight. At the beginning of the program,
the user will be asked to enter the height in centimeters and weight in kilogram. After that,
the program will carry out the conditions. If the height is less than 165 (cm) OR the weight
is less than 60 (kg) then the text “You failed the physical exam” will be displayed. The
logical OR operator made a decision in which if the applicant met any of the two conditions
then he/she failed the physical exam. In real life, this means that even if the applicant’s
height is greater than 165 cm, he/she can still fail the physical exam when his/her weight
is less than 60 kg (the second condition is met). Observe that the variables Height and
Weight are declared as real. This means that the user can also input data that have
decimal places such as 165.10 or 60.50.
• Example 3: Application of equal relational operator (=), logical NOT operator, and if-then-
else statement.

Figure 4. Example Conditional Statement-3


• Code explanation
Example 3 shows a program that determines if the password entered by a user
is correct or incorrect. Before the beginning of the program block, the variable “password”
is declared as an integer, this would mean that the password being required by the
program is numerical in nature and has no decimal places (such as unique pin in ATMs).
At the beginning of the program block, the user would need to enter a password. After that
decisions will be made. Logically, if the user entered the correct password which is 1234,
the text “Welcome to your account” will be displayed. But since the logical NOT is
introduced in the condition, this logical operation will be reversed. This means that if the
user entered 1234, the correct password, the statement “Wrong password, please try
again” would be displayed instead of the first message. This is how logical NOT reverses
logical operations.

Prepared: Noli A. Esmeña, Teacher I, Tayug NHS (2021) 3


Part I: Activity Proper
Practice Questions
Directions: Answer the following questions in your own words. Write your answers on a piece
of paper.
1. How helpful are relational and logical operators in establishing a clear conditional
statement?
2. When should you use the if-then statement and if-then-else statement?

Part II: Summative Test (Written Works 50% - Graded)


Writing a Program with Conditional Statement (15 pts)
Directions: Read and understand the programming problem stated below and create a
program that solves/addresses it. Write your program on a piece of paper. Figure 5 is created
for you to show the expected flow of the program.
Problem: Create a program that indicates if the pH level entered by a user is
acidic, basic, or neutral. A pH level of 7 is neutral, a pH level of less than 7 is acidic, and a
pH level of greater than 7 is basic.

Figure 5. Expected program flow

Rubric
Points 0 point
5 points 3 points 1 point
Criteria
The program was The program needs The program needs No
Correctness of able to display the minimal revisions to full revision to output
Program (x2) expected output display the expected display the expected
output output
The output is The output is The output is No
Promptness submitted before submitted the day submitted days after output
the due date after the due date the due date

Note: The due date will be announced by your teacher.

Prepared: Noli A. Esmeña, Teacher I, Tayug NHS (2021) 4


Part III: Performance Task (50% - Graded)
Explaining a Conditional Statement (20 pts)
Directions: In Part II, you have created a program that indicates if a pH level entered by a user
is acidic, basic, or neutral. In this part, you are going to add explanations to the program you
have created. Explanations should be given for every line of code. Figure 6 shows an example
of how you can cite your explanations. You can also express your explanations in other ways
as long as (1) the explanation is clear, (2) each line of code has an explanation. Write your
explanations on a piece of paper.

Explanation No. Code Explanation

1 This line of code indicates the title of the program


2 These lines of code declare the constant value which is Pi with a value
of 3.141592654
3 This line of code declares the variables r and c as real numbers. The
variable r will be used to store the value of r which will be entered by the
user. While c will be used to store the correct circumference value.
4 The writeln function is used to show a text. The text should be enclosed
with parenthesis and single quotation marks.
5 The readln function is used to read a line of input from a user
6 This line indicates the formula where operators are mainly used.
7 The writeln function allows a text to be displayed, while the comma adds
values to be displayed (which in this code is the circumference).
8 The readln function in this line pauses the code so that the user can first
read the result (the circumference) before exiting.
Figure 6. Sample explanation to a program
Note: This example is lifted from Worksheet 3
Rubric

Points 0
5 points 3 points 1 point
Criteria point
The explanation is The explanation The explanation is
Comprehensiveness very is comprehensive not No
and correctness (x2) comprehensive with minimal comprehensive output
with no errors. errors. with many errors.
The language Major revisions
Few revisions are
used is simple are needed to
needed to make
Clarity which makes the make the
the explanation
explanation very explanation
clearer.
clear. clearer.
The output is The output is The output is
No
Promptness submitted before submitted the day submitted days
output
the due date after the due date after the due date
Note: The due date will be announced by your teacher.

Prepared: Noli A. Esmeña, Teacher I, Tayug NHS (2021) 5


REFERENCES
1. TutorialsPoint. (2021). Pascal – Decision Making.
https://www.tutorialspoint.com/pascal/pascal_decision_making.htm
2. TutorialsPoint. (2021). Pascal - Program Operators.
https://www.tutorialspoint.com/pascal/pascal_operators.htm

Prepared by: Checked by: Noted by:

NOLI A. ESMEÑA SHERYL D. SIBAYAN REVELYN C. CAMACHO, Ph. D.


Teacher I Master Teacher II Head Teacher VI, Science Dept.

Prepared: Noli A. Esmeña, Teacher I, Tayug NHS (2021) 6

You might also like