Selection (IF)

True or False?

When programming we often want the computer to make decisions of which path to follow.

To make a decision the program will need to compare two values.

IF the condition is true it will follow one path, ELSE (if false) it will follow another path.

To select a path we use the IF or the IF… ELSE… blocks.

The selection blocks need to use comparative operators to make their decisions.

Comparative Operators

Comparative operators are symbols used to decide true or false conditions by comparing values (e.g <, >, =).

Watch the video below to see how to use conditional statements.

Scratch 7 - Selection Part 1.mov

Take a look at the example code below.

What will the output be?

Click the Green Flag to see if you were right.

In the example above, the program checks to see if the number stored in variable num1 is the same as the number stored in the variable num2. If it is, the answer is TRUE else the answer is FALSE.

Watch the video below to see how to use the IF Statement block.

Scratch 7 - Selection Part 2.mov

Challenges

The files you will need to help you can be downloaded at the bottom of the page.

Bigger Than...

Create a program that asks the user to enter a number.

You will need to store their answer in a variable.

The program should tell the user if the number they enter is bigger than 64..

Bus Pass

Create a program that asks the user to enter their age.

You will need to store their answer in a variable.

The program should tell the user if they get a free bus pass (they are over the age of 64).

Quiz Show

Create a program that asks the user “What is the capital of France?”.

You will need to store their answer in a variable.

The program should tell the user that they got the question right IF their answer equals ‘Paris’. Otherwise it should tell them the correct answer.

What's the difference?

Create a program that will ask the user for two numbers.

The program should tell them which is the biggest number or if the numbers are the same.

Key Words

Comparative Operator

Symbols used to decide true or false conditions by comparing values (e.g. <, >, =)

Selection Statement

A programming structure that is used to choose what happens next in a program. Relies on a conditional statement being true.

Files

Below are the files you will need to complete the challenges.