This website uses cookies to ensure you get the best experience on our website.
Ohbot
  • OH
    • Educators
    • Makers
  • About
    • Our Robots
    • Our Story
    • Follow Us
    • Contact
  • Shop
    • All Robots
    • Ohbot Assembled
    • Ohbot Kit
    • Picoh
    • OhbotApp2
    • Accessories
    • Resellers
  • Get Started
    • Ohbot Assembled
    • Ohbot Kit
    • Picoh
    • Accessories
    • Technical Notes
    • Languages
    • Support
  • Learn
    • Picoh
    • Ohbot
    • AI
    • Robot Work
    • Share

<-PICOH SCHEME

Year 5 - Lesson 3: Nesting Ifs

Picture
Learning Intention
 
I can use nested if-then-else instructions in my program.

Introduction
​

In the last lesson we created quiz programs that used conditionals. Each time the program runs the same questions are always asked; Question 1, and then Question 2, then Question 3.
Picture
It can be useful to have a program where the next question Picoh asks depends on how the previous one has been answered. You might be familiar with this when you ask a personal assistant to set an alarm. Only if you ask it to set an alarm will the question ‘What time would you like me to set the alarm for?’ be asked. Or perhaps you have played a maths game that has become more difficult as you get more answers right. The programs select the next question based on how the previous one was answered.

For us to do this we can nest If-then-else conditional instructions like this:
Picture
Ask students which conditions need to be set true or false to run each of the action blocks Do1 to Do7.

Let’s look at how this can be used to make the second quiz question more difficult if the first answer is answered correctly, and easier if it is not. This is the code from the previous lesson.
Picture
Now here's a trickier follow up question:
Picture

Can you work out where in the code the sequence would need to go so that the trickier question is only asked if the answer to the first question is right?

​And how about this code for a question that is easier than the first one. 
Picture

Can you work out where this could be put into the code so that it is only asked if the answer to the first question is wrong?

We can nest further of course with the answer to the second question determining the third question that is asked. Before long things can get a bit overloaded as the code becomes enormous. 

Activity 1:

Can you program Picoh to run a quiz that always asks at least three-questions with more difficult questions if the user gets answers right and easier questions if the user gets answers wrong? 

Extension:

Can you add a score based on the number of questions that are answered correctly?

You could try creating a variable, setting it to zero at the start and increasing it each time a correct answer is given

Plenary:

Nesting can become very unwieldy when you go beyond several layers deep. How many if-then-else 
conditionals do you think would be needed to create a quiz that always asked at least 6 questions?
​
Is there another way of organising a program?

Picture
OH
Educators
Makers

About
Our Story
Follow Us
Consultancy
Contact
Shop
All Robots
Ohbot Assembled
Ohbot Kit
Picoh
OhbotApp2
Accessories
Resellers
Get Started
​Ohbot Kit
Ohbot Assembled
Picoh
Accessories
Technical Notes

Languages
Support

Learn
Picoh

Ohbot
AI
Robot Work
Share
Picture
Picture
Picture
Picture
Picture
​Ohbot Ltd. 2A Halliday's Mill, London Road, Chalford, Gloucestershire, GL6 8NR, UK
Copyright © Ohbot Ltd.  All rights reserved.
​Ohbot
® is a registered trademark of Ohbot Ltd.
  • OH
    • Educators
    • Makers
  • About
    • Our Robots
    • Our Story
    • Follow Us
    • Contact
  • Shop
    • All Robots
    • Ohbot Assembled
    • Ohbot Kit
    • Picoh
    • OhbotApp2
    • Accessories
    • Resellers
  • Get Started
    • Ohbot Assembled
    • Ohbot Kit
    • Picoh
    • Accessories
    • Technical Notes
    • Languages
    • Support
  • Learn
    • Picoh
    • Ohbot
    • AI
    • Robot Work
    • Share