Search Header Logo
Unit 9 Key programming concepts T2 Sequence & selection

Unit 9 Key programming concepts T2 Sequence & selection

Assessment

Presentation

Computers

10th Grade

Practice Problem

Hard

Created by

Michael Harrington

FREE Resource

17 Slides • 13 Questions

1

media

Unit 9 Topic 2

Unit 9 Topic 2

2

media

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 Blank

Objectives

What is the missing word <?>

Use selection and <?> selection statements

4

Fill in the Blank

Objectives

What is the missing word <?>

Use NOT, AND and OR when creating
<?> expressions

5

Fill in the Blank

Objectives

What is the missing word <?>

Use of logical <?> including:

6

media
media
media

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

media
media
media

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

media
media

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

media
media
media

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

media
media

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?

1

AND

2

iteration

3

NOT

4

Sequence

5

selection

12

Multiple Select

What are three operators used in Boolean expressions?

1

AND

2

OR

3

NOT

4

Sequence

5

selection

13

media
media
media

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

15

media
media

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

media
media

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

Question image

What is the price for an adult on Saturday?

1

2.00

2

4.00

3

2.50

4

0

18

Multiple Choice

Question image

What is the price for a child on Sunday?

1

2.00

2

4.00

3

2.50

4

0

19

Multiple Choice

Question image

What is the price for Mr H on Saturday ?

1

2.00

2

4.00

3

2.50

4

0

20

media
media

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

media
media

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

media
media
media

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

Question image

If x = 3 and y = 5, choose all the statements that evaluate to True.

1

x < y

2

y > -9

3

2 * x == y

4

y MOD x == 3

(MOD finds the remainder)

24

Multiple Choice

Question image

Evaluate:

2 < 3 And ( Not 3 > 2)

1

True

2

False

25

media
media

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

media
media

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

Labelling

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

Drag labels to their correct position on the image

"W"

"D"

"Y"

"X"

other

"S"

"A"

Y

28

media
media

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

Labelling

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

Drag labels to their correct position on the image

Output

Assign Op

Math Op

Boolean

Comparison

30

media
media
media

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

media

Unit 9 Topic 2

Unit 9 Topic 2

Show answer

Auto Play

Slide 1 / 30

SLIDE