Computer Science
4.2 Maze Game -Day 2
Continually test condition
Forever Loop has two main uses:
……….forever
2. Continually check if a condition is true,
……….forever
How long is forever?
from start to end of a program:
from to
PseudoCode
If touching color green | If touching end Sprite | If Reset |
| | |
PseudoCode
A. If touching color green | B. If touching end Sprite | C. If Reset |
Go to start location | Celebrate! Say something…. Do something….. |
Go to start Location |
If touching green wall….
“Touch” is one of our 5 senses,
So touch commands are under Sensing.
How to choose color….
How to choose
color….
Click region on stage with desired color.
(See video).
B. Condition: True or False?
If touching End Sprite….
…..make end level reward(s)
Use Broadcast,
to call multiple things simultaneously:
eg Speak and Dance
Pause: Work on your maze game.
Next slides are related to exit slip.
Learning Objective:
Repeatedly test "conditional statement"
by putting it in a forever loop.
…………..………….but………………...
What is a Conditional Statement?
Conditional Statements:
Conditional Statements evaluate a condition: � if condition is TRUE code does one thing,
if condition is FALSE code does a different thing.
Condition: True or False?
Condition
Path 1
Path 2
next command
Conditional Statements:
Conditions must be evaluated repeatedly incase they change state, not just tested once. To test a condition repeated put into a “Forever Loop”.
Condition: True or False?
Does this code do the same thing?
See example in a scratch project