
Unit 9 Key programming concepts T2 Sequence & selection
Presentation
•
Computers
•
10th Grade
•
Practice Problem
•
Hard
Michael Harrington
FREE Resource
17 Slides • 13 Questions
1
Unit 9 Topic 2
Unit 9 Topic 2
2
Unit 9 Topic 2
Unit 9 Topic 2
Objectives
• Use selection and nested selection statements
• IF statements
• CASE statements
• Use NOT, AND and OR when creating
Boolean expressions
• Use of logical operators including:
• =
• <
• <=
• >
• >=
• <>
3
Fill in the Blanks
Objectives
What is the missing word <?>
Use selection and <?> selection statements
4
Fill in the Blanks
Objectives
What is the missing word <?>
Use NOT, AND and OR when creating
<?> expressions
5
Fill in the Blanks
Objectives
What is the missing word <?>
Use of logical <?> including:
6
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
Starter
• Control structures choose the direction which a
program will take based on the values of variables
• What are the three
basic control
structures used
in programming?
• What are three
operators used
in Boolean
expressions?
7
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
Starter
• What are the three basic control structures used
in programming?
• Sequence, selection and iteration
• What are three operators used in
Boolean expressions?
• AND, OR, NOT
8
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
Sequence
• The statements are executed
one by one in the order they
are written:
mark1 <- 78
mark2 <- 67
total <- mark1 + mark2
average <- total / 2
OUTPUT average
9
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
Selection
• An IF statement is a selectionstatement
• The next statement to be executed depends on
whether the condition being tested is True or False
IF average >= 80
THEN
OUTPUT "Distinction"
ELSE
OUTPUT "Pass"
ENDIF
10
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
Comparison expressions
• The condition average >= 80is a
Boolean expression
• The outcome will always evaluate to TRUE or FALSE
• Comparison operators include
=
equal to
<>
not equal to
>
greater than
<
less than
• What are two other comparison operators?
• Why do you need to be careful with = in real
programming languages?
11
Multiple Select
What are the three basic control structures used in programming?
AND
iteration
NOT
Sequence
selection
12
Multiple Select
What are three operators used in Boolean expressions?
AND
OR
NOT
Sequence
selection
13
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
Boolean expressions
• Here is a full list of comparison operators
•
• A single = is often used for assignment - e.g. age = 14
Comparison
operators
Meaning
Pseudocode
example
Result
Notes
=
Equal to
5 = 5
True
Many languages
use a double ==
<>
Not equal to
5 <> 5
False
Many languages
use !=
>
Greater than
5 > 5
False
>=
Greater than or equal
to
5 >= 5
True
<
Less than
5 < 5
False
<=
Less than or equal to
5 <= 5
True
14
Match
Match the following
<=
<
>=
<>
>
Less than or equal to
Less than
Greater than or equal to
Not equal to
Greater than
Less than or equal to
Less than
Greater than or equal to
Not equal to
Greater than
15
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
If statements
• If statements allow different branches to be executed
based on the result of a Boolean expression
IF average >= 60
THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
16
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
Nested if statements
• If statements may be nested:
IF member = "child"
THEN
IF day = "Saturday"
THEN
swimPrice ← 2.00
ELSE
swimPrice ← 2.50
ENDIF
ELSE
swimPrice ← 4.00
ENDIF
• What is the price for an adult on Saturday?
•What is the price for a child on Sunday?
17
Multiple Choice
What is the price for an adult on Saturday?
2.00
4.00
2.50
0
18
Multiple Choice
What is the price for a child on Sunday?
2.00
4.00
2.50
0
19
Multiple Choice
What is the price for Mr H on Saturday ?
2.00
4.00
2.50
0
20
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
Complex Boolean expressions
• Boolean expressions can include the Boolean
operators AND, OR and NOT
• For example:
IF (mark < 0) OR (mark > 100) THEN …
Operator
Description
AND
Returns TRUE if both conditions are TRUE
OR
Returns TRUE if either of the conditions are TRUE
NOT
A TRUE expression becomes FALSE and vice versa
21
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
True or False?
• Complete the table:
Mark1
Mark2
Condition
True or
False?
80
67
(mark1 >= 80) AND (mark2 >= 80)
82
80
(mark1 >= 80) OR (mark2 >= 80)
35
(mark1 > 30) OR (mark1 < 50)
65
(mark1 < 30) OR (mark1 > 80)
0
75
NOT(mark1 > 50) AND (mark2 > 50)
65
85
NOT(mark1 < 60) AND NOT (mark2 < 80)
Which one is the misconception?
Lots of beginners make this mistake!
22
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
True or False?
Mark1
Mark2
Condition
True or
False?
80
67
(mark1 >= 80) AND (mark2 >= 80)
False
82
80
(mark1 >= 80) OR (mark2 >= 80)
True
35
(mark1 > 30) OR (mark1 < 50)
True
65
(mark1 < 30) OR (mark1 > 80)
False
0
75
NOT(mark1 > 50) AND (mark2 > 50)
True
65
85
NOT(mark1 < 60) AND NOT (mark2 < 80)
True
• Complete the table:
23
Multiple Select
If x = 3 and y = 5, choose all the statements that evaluate to True.
x < y
y > -9
2 * x == y
y MOD x == 3
(MOD finds the remainder)
24
Multiple Choice
Evaluate:
2 < 3 And ( Not 3 > 2)
True
False
25
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
CASE statements
• Writing out lots of IF statements can be tedious
• CASE statements will branch depending on many different
possible values for an identifier
INPUT KeyPress
CASE OF KeyPress
"1" : showMenu()
"2" : showInstructions()
"3" : playGame()
"Q" : quitGame()
OTHERWISE OUTPUT "Not a valid option"
ENDCASE
26
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
CASE statements
• CASE statements are not available in some
programming languages such as Python
• A drawing program lets the user move the pen
position when the following keys are pressed:
• W subtracts 1 from the variable Y Position
• S adds 1 to the variable Y Position
• A subtracts 1 from the variable Xposition
• D adds 1 to the variable Xposition
• Create pseudocode using CASE statements to carry
out the above
27
Labeling
A drawing program lets the user move the pen position when the following keys are pressed:
W subtracts 1 from the variable Y Position
S adds 1 to the variable Y Position
A subtracts 1 from the variable X position
D adds 1 to the variable X position
Y
"X"
other
"D"
"Y"
"W"
"S"
"A"
28
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
Plenary
• Look at the following code:
hourlyRate <- 15.50
INPUT hoursWorkedInWeek
IF hoursWorkedInWeek > 168
THEN
OUTPUT "That’s impossible"
ELSE
totalPay <- hoursWorkedInWeek * hourlyRate
OUTPUT totalPay
ENDIF
• With a partner, identify each of the following:
• A comparison operator, a Boolean expression a selection
structure, a sequence, three assignment operators, an output
statement, one mathematical operator
29
Labeling
identify each of the following:
A comparison operator,
a Boolean expression
a selection structure,
a sequence,
three assignment operators,
an output statement,
one mathematical operator
Comparison
Math Op
Output
Assign Op
Boolean
30
Unit 9 Topic 2
Unit 9 Topic 2
Sequence and selection
Unit 9 Key programming concepts
Worksheet 2
• Now complete Task 1,2 & 3 on Worksheet 2
Unit 9 Topic 2
Unit 9 Topic 2
Show answer
Auto Play
Slide 1 / 30
SLIDE
Similar Resources on Wayground
24 questions
Fungsi-fungsi pada program pengolah angka
Presentation
•
10th Grade
21 questions
Molecular Geometry
Presentation
•
10th Grade
23 questions
Python Strings and Character Encoding
Presentation
•
10th Grade
24 questions
Email Etiquette
Presentation
•
10th Grade
24 questions
MAIL MERGE
Presentation
•
10th Grade
23 questions
Down in the Deep
Presentation
•
10th Grade
26 questions
บทที่ 4 อาชีพในยุคดิจิทัล (อาชีพ)
Presentation
•
KG
22 questions
Dimensional Analysis
Presentation
•
10th Grade
Popular Resources on Wayground
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
6 questions
Rule of Law
Quiz
•
6th - 12th Grade
22 questions
Continents and Oceans
Quiz
•
5th Grade
10 questions
Movie Trivia
Quiz
•
KG - 2nd Grade
15 questions
Rounding Decimals
Quiz
•
5th Grade
Discover more resources for Computers
16 questions
Module 1 Topic 2 Vocabulary Test
Quiz
•
9th - 12th Grade
10 questions
Navigating Digital Citizenship and Online Safety
Interactive video
•
6th - 10th Grade
18 questions
[AP CSP] Python Coding: Conditionals + List + Algo Dev
Quiz
•
9th - 12th Grade
20 questions
Early Computing
Quiz
•
7th - 12th Grade