Control block(Class 4)
Importance of Control Blocks:
Control blocks are the logic and timing engine of your Scratch
project. They allow you to:
● Sequence actions: Make things happen in a specific order.
● Create loops: Repeat actions efficiently.
● Make decisions: Respond differently based on various conditions.
● Manage timing: Control when things happen and for how long.
● Handle parallelism: Run multiple scripts simultaneously using
forever loops or events.
● Generate objects dynamically: Use cloning to create complex
interactions.
wait [number] seconds
2
● What it does: Pauses the script for the specified number of seconds.
● Use case: Useful for timing actions, creating delays between movements or
dialogues, or pacing animations.
● Example: move [10] steps, wait [0.5] seconds, say [Hello!] for [2]
seconds
repeat [number]
● What it does: Executes the blocks inside its C-shaped mouth a
specified number of times.
● Use case: Repeating actions like walking steps, drawing a shape,
or playing an animation sequence a fixed number of times.
Example: To draw a square:
Code snippet
repeat (4)
move (100) steps
turn (90) degrees
3
forever
● What it does: Executes the blocks inside its C-shaped mouth
continuously, without stopping, until the project is manually
stopped.
● Use case: The backbone of many interactive projects. Used for
continuous movement, checking conditions repeatedly, running
background music, or handling user input in a game loop.
Example:
Code snippet
forever
if <key [right arrow] pressed?> then
change x by (5)
end
if <key [left arrow] pressed?> then
change x by (-5)
end
if <condition> then
● What it does: Executes the blocks inside its C-shaped mouth only
if the Boolean (true/false) condition is met. If the condition is
false, the blocks inside are skipped.
4
● Use case: Making decisions. For example, checking if a sprite
is touching another sprite, if a certain key is pressed, or if
a variable has reached a certain value.
● Example: if <touching [color red]?> then play sound [GameOver]
end
if <condition> then else
● What it does: Executes one set of blocks if the condition is true, and a different set of
blocks if the condition is false.
● Use case: Providing alternative actions based on a decision. For example, if a character
touches a coin, add to score; else if it touches an enemy, lose a life.
Example:
Code snippet
if <answer = [cat]> then
say [You're right!]
else
say [Try again.]
wait until <condition>
● What it does: Pauses the script's execution until the specified Boolean condition
becomes true. Once true, the script continues.
● Use case: Waiting for a specific event to occur before proceeding. For example,
waiting for a key press, a sprite to reach a certain position, or a timer to run out.
● Example: wait until <key [space] pressed?>
repeat until <condition>
● What it does: Executes the blocks inside its C-shaped mouth
repeatedly until the specified Boolean condition becomes true. As
long as the condition is false, it keeps repeating.
● Use case: Similar to forever, but with an exit condition. Used
for game loops that continue until a win/lose condition is met,
or for a character to move until it hits a wall.
5
Example:
Code snippet
repeat until <touching [edge]?>
move (5) steps
stop [all]
● What it does: Stops scripts. It has a dropdown with three
options:
○ all: Stops all running scripts in the entire project. This
is often used for "Game Over" screens or when the project
finishes.
○ this script: Stops only the script that contains this block.
Other scripts in the same sprite or other sprites will
continue running.
○ other scripts in sprite: Stops all other scripts within the
same sprite that are currently running, but the script
containing this block continues.
● Use case: Controlling the flow of multiple scripts, ending
games, or managing sprite behaviors.
● Example: stop [all] (at the end of a game) or stop [this
script] (after a character finishes an animation).
when I start as a clone (Hat block)
● What it does: This is a "hat" block that starts a script
specifically for a newly created clone of a sprite.
6
● Use case: Defines the behavior of cloned sprites, which are
copies of an original sprite. Each clone can then act
independently.
● Example: when I start as a clone, go to random position, show
create clone of [myself]
● What it does: Creates a copy (clone) of a specified sprite.
The drop down allows you to select "myself" (the sprite running
the script) or any other sprite in the project.
● Use case: Generating multiple similar objects, like bullets,
falling items, enemies, or particles, without having to create
many separate sprites.
● Example: create clone of [Bullet] (every time the player
shoots)
delete this clone
● What it does: Removes the clone that is currently running this script from the stage.
● Use case: Essential for managing clones and preventing projects from becoming
cluttered or slow. Used when a clone hits something, goes off-screen, or is no longer
needed.
● Example: if <touching [edge]?> then delete this clone
7