Minds On

Conditional statements and coding

Brainstorm

Brainstorm

Brainstorm and record your thoughts using a method of your choice:

  • What are conditional statements?
  • How are conditional statements used?
  • How do they relate to coding?

Action

Task 1: Defining conditional statements

A conditional statement is a type of coding instruction.

This type of instruction is used to compare different values and make decisions based on those values.

Conditional statements will inform a program to do something depending on whether something is true or false.

Conditional statements are demonstrations of binary logic:

  • yes or no
  • true or false
  • 1 or 0

These statements usually begin with words such as: if/then

If the conditional statement is true, then there will be an interruption in the code. A new direction will be taken, or the program might end.

Conditional statements allow for a variety of outcomes in coding.

One example many individuals experience daily is with a password. When you are putting in a password into a computer or phone, this uses a conditional statement. If you have entered the correct password, you will be granted entry into your computer, phone, or program. If you do not enter the correct password, you will not be allowed in.

Are there any other examples you can think of where conditional statements are used in real life? Do you think that facial recognition on a cellphone would be an example of a conditional statement?

Record your thoughts using a method of your choice.

Task 2: Conditional statement game

Create some conditional statements and some effects. You should create one conditional statement and three effects.

Example:

  • Conditional Statement: If it snows
  • Effects: Then there will be a snow day; then a dog will bark; then a monkey will throw a banana.

Complete the Conditional Statements Game in your notebook or using the following fillable activity document. If you wish, you can also use any method of your choice such as a mind map, text to speech, or audio recording. The conditional statements and effects do NOT need to be related to each other. Be as creative as possible!

Press the ‘Activity’ button to access Conditional Statements Game. 

Task 3: Using conditional statements

Here is an example of a code using a conditional statement.

A 5 x 5 grid with a character in one square and a bunch of bananas in another. There are few brown squares. Also, there is a chart with a conditional statement and code that reads:

  • Start program
  • If there is: banana
  • Do: pick the banana
  • Else: move forward

Press ‘Answer’ to reveal a possible explanation to check your understanding.

The outcome changes depending on what the person does. If they arrive at the square with the bananas, they will pick the banana. If they arrive at a square that doesn’t have bananas, they will continue to move forward.

The program is informing the character that if there is a banana, they should pick it. If not, they should move forward. The person cannot complete both tasks.

How does the outcome change depending on the condition? Record your ideas digitally, orally, or in print.

Create your own code

Try to create your own code using conditional statements. Be creative.

Create your own situation. Practice using conditional statements within your code. Decide on the starting and ending points as well as the options for your statements.

Record your code digitally, orally, or in print.

Consolidation

Task: Code creation

Create your own situation and write a code to complete a specific task. Consider the example of an escape room, completing a task or craft, or playing a sport. Decide where the start and end points are as well as different conditional statements.

Record your code digitally, orally, or in print.

Think about your learning

Answer the below questions digitally, orally, or in print.

  • Why are conditional statements useful in coding?
  • Can you think of other scenarios in which you would need conditional statements?

Reflection

As you read through these descriptions, which sentence best describes how you are feeling about your understanding of this learning activity? Press the button that is beside this sentence.

I feel...

Now, record your ideas using a voice recorder, speech-to-text, or writing tool.

Connect with a TVO Mathify tutor

Think of TVO Mathify as your own personalized math coach, here to support your learning at home. Press ‘TVO Mathify’ to connect with an Ontario Certified Teacher math tutor of your choice. You will need a TVO Mathify login to access this resource.

TVO Mathify (Opens in a new window)