Mastering iteration structures, decision trees, collision sensing, and boolean logic in Scratch.
repeat N), Infinite (forever), and Condition-Controlled (repeat until) loops.if-then and if-then-else conditional statements.and, or, and not operators.Code executes line 1, then line 2, then line 3, then stops. Cannot repeat actions or adapt to player input dynamically.
Loops keep scripts running continuously; Conditionals evaluate live game events (key presses, wall hits, timer limits).
Zain built a maze game. He wrote: when green flag clicked → if touching [Wall] then turn 180 degrees. But when the green flag is clicked, his cat walks right through the maze wall!
if block run only once at millisecond 0 and then shut off forever?repeat (10)Executes enclosed blocks a fixed number of times, then moves to the next block underneath.
foreverRepeats enclosed blocks continuously until the Stop sign is pressed or stop all is called.
repeat until <>Keeps looping until a specific Boolean condition becomes TRUE.
if-then vs if-then-elseif <condition> thenSingle branch: If condition is true, execute inner blocks. If false, skip inner blocks completely.
if <condition> then ... elseDual branch: Guaranteed action! Does Branch A if true, or Branch B if false.
if-then-else ExecutionCheck Boolean: e.g. <touching [Enemy]?>
Execute Branch A: Loose 1 Life & Reset Position.
Execute Branch B: Keep walking forward.
Continue to next block outside conditional.
Hexagonal blocks return either TRUE or FALSE.
<touching [Sprite]?><touching color [#FF0000]?>
<key [space] pressed?><key [up arrow] pressed?>
<(score) > 50><(timer) = 0>
The green operator blocks in Scratch perform the exact same Boolean operations as Chapter 2 hardware logic gates.
< () and () >True ONLY if both condition A and condition B are met.
< () or () >True if at least one condition is met.
< not () >Flips True to False, and False to True.
touching sprite vs touching colortouching [Sprite]?Fast and reliable! Works regardless of background colors or stage graphics changes.
touching color [#00FF00]?Can fail if backdrop shade changes slightly or color picker is off by 1% hue!
Useful for grid generation, repeating animation cycles inside continuous game loops.
Placing if key space pressed directly under green flag. It checks key press in 0.001s and ends!
Wrapping the if block inside a forever loop ensures it checks key presses 60 times every second!
A sprite starts with X = 0.
Code: repeat 4 { change X by 15 }
Given: Score = 15 | Lives = 0
Condition A: <<(Score) > 10> and <(Lives) > 0>>
Condition B: <<(Score) > 10> or <(Lives) > 0>>
An enemy sprite patrols left and right until it detects the player sprite, then plays a warning alarm.
Build a coin that glides around, giving points when collected, but disappears if the bomb touches it.
if key space pressed block is NOT inside a forever loop?repeat N (fixed), forever (continuous), repeat until (conditional).if-then (single branch), if-then-else (dual choice).if blocks in a forever loop.and, or, not for precise multi-condition game rules.In your notebook, sketch a flowchart for:
A character moving forward continuously, but IF touching a spike sprite, THEN play "ouch" sound and go back to (0,0), ELSE change costume to walk.