Year 7 › Scratch I: Programming essentials › Lesson 3 of 5
Year 7 · Spring 2 · Scratch I: Programming essentials Selection: if / if-else and conditions
Topic 11 Algorithms
KS3 Computing · An algorithm is a precise, step-by-step plan to solve a problem. Computational thinking turns a messy problem into one. Every algorithm is built from just three things: sequence, selection and iteration.
Programming Computational Thinking Cambridge Lower Secondary Computing 0860
You will learn to Explain what a condition is: a question with a true or false answer. Use if … then to run blocks only when a condition is true. Use if … then … else to choose between two paths. Identify the diamond shape that shows a decision in a flowchart.
Success criteria I can make a sprite react when it touches the edge. I can make a sprite say 'You win' when the score is more than 10. I can predict which path an if-else block will take.
Algorithm Precise, ordered, finite steps to solve a problem.
Decomposition Breaking a problem into smaller ones.
Abstraction Ignoring detail that doesn't matter for the problem.
Sequence · selection · iteration Steps one after another. First this, then this.
Pseudocode Code-like writing for algorithms, without strict rules.
Trace table Records variable values step by step to check logic.
Variable A named place in memory that holds a value.
Conditions: yes or no questions Selection means the program chooses what to do next.
It chooses by asking a condition . A condition is a question with only two answers: yes or no.
Computers say true for yes and false for no.
Is the sprite touching the edge? Is the score more than 10? Is the space key pressed? ★ RememberIn Scratch, conditions are the pointed, six-sided blocks. They only fit into the pointed holes.
if … then: do it only when true when this sprite clicked
change [score v] by (1)
if <(score) > (10)> then
say [You win!]
end The sprite is clicked. The score goes up by 1. Scratch asks: is the score more than 10? True: it runs the blocks inside, so the sprite says 'You win!'. False: it skips the blocks inside and carries on. e.g. ExampleBounce off the edge: if <touching (edge v)?> then put turn right (180) degrees inside.
if … then … else: two paths ask [What is 6 × 7?] and wait
if <(answer) = (42)> then
say [Correct!]
else
say [Try again.]
end The answer block holds what the player typed.
If the condition is true, the top path runs. If it is false, the else path runs.
★ RememberWith if … else, exactly one path runs. Never both, never neither.
In a flowchart, a decision is a diamond . Two arrows leave it, labelled Yes and No.
Comparing numbers in Scratch ! Watch outScratch has no 'more than or equal to' block. 10 > 10 is false . To include 10, use score > 9 for whole numbers.
e.g. Worked exampleThe score is 10. The script says: if score > 10 then say 'You win!'. Does the sprite say anything?
Ask the condition: is 10 more than 10? No. 10 is equal to 10, not more than it. So the condition is false, and Scratch skips the say block. To win at 10, change the condition to score > 9.
Mark this lesson as done Saved on this device.
← Previous lesson Variables: score and lives Next lesson → Iteration: count-controlled and condition-controlled loops