ICSOC-8.11.4 Control Flow, Looping, and Decision Logic (M)

Easy

ICSOC-8.11.4.1 Timing Delays: Thread Yielding, Clock Latency, and Frame-Synchronous Pauses

Timing Delays: Thread Yielding, Clock Latency, and Frame-Synchronous Pauses

In Scratch 3.0, the “wait ( ) seconds” block within the Control palette (color-coded warm amber-gold) functions as a foundational synchronous timing delay and thread-yielding primitive. When an executing script encounters “wait (n) seconds”, the Scratch execution engine registers a temporal timestamp (current_time + n) and suspends instruction advancement along that specific script stack. Crucially, this delay is non-blocking to the rest of the project: the Scratch virtual machine continues executing other parallel threads and rendering stage graphics at its standard 30 frames-per-second (FPS) refresh rate while the paused script yields its CPU execution slice.

Under the hood, timing accuracy is governed by the underlying JavaScript runtime event loop and display refresh intervals. Entering a fractional delay of 0 seconds (or values below approximately 0.033 seconds) does not skip execution entirely; instead, it yields control for exactly one virtual machine execution step (one frame tick of ~33 milliseconds). This mechanism provides developers with a reliable technique to synchronize multi-threaded sprite actions, pace sequential costume animations, and enforce orderly execution order across parallel scripts without triggering UI freezes or unresponsive script warnings.

Easy
In Scratch 3.0, which category and block color contains the [wait () seconds] instruction?
Option A is correct because the [wait () seconds] block is a timing and flow management instruction situated in the Control category, characterized by its warm amber-gold color. Option B is incorrect because Events blocks are yellow hat and broadcast blocks. Option C is incorrect because Sensing blocks are light blue/cyan reporter blocks. Option D is incorrect because Motion blocks are dark blue movement instructions.
Medium
When a sprite script encounters the block [wait (2) seconds], how does the Scratch virtual machine handle other running scripts in the project?
Option A is correct because Scratch utilizes cooperative multi-threading; the [wait ( ) seconds] block causes only the specific calling thread to yield its execution slice while other running scripts and visual rendering continue operating at normal 30 FPS tick cycles. Option B is incorrect because Scratch does not freeze the entire virtual machine. Option C is incorrect because input events and sensing continue to be polled. Option D is incorrect because the script resumes from the subsequent block rather than resetting.
Tricky
What occurs at the runtime engine level when a Scratch programmer executes the block [wait (0) seconds] inside an active script?
Option A is correct because in Scratch’s execution model, specifying [wait (0) seconds] (or any duration under one frame step) functions as an intentional thread yield; the runtime pauses the current stack for one frame cycle (~1/30th second or ~33 ms) to allow other threads and display updates to process before continuing. Option B is incorrect because it does not skip the yield step. Option C is incorrect because 0 is a valid numeric argument. Option D is incorrect because 0 seconds does not cause an infinite halt.
Easy

ICSOC-8.11.4.2 Count-Controlled Iteration: Deterministic Looping, Loop Counters, and Nested Cycles

Count-Controlled Iteration: Deterministic Looping, Loop Counters, and Nested Cycles

The “repeat (n)” block introduces count-controlled iteration—a fundamental algorithmic control structure in which a designated sequence of nested blocks executes for a predetermined, finite number of iterations. Designed with a C-shaped clasp (a “wrap-around” block), the repeat structure encloses inner statements and maintains an internal integer iteration counter managed autonomously by the runtime engine. If the parameter n is supplied as a floating-point number, Scratch truncates or rounds the value to an integer, and if n is less than or equal to 0, the loop body is bypassed entirely without throwing a runtime error.

Each iteration of an unconstrained loop that causes visual stage modifications automatically introduces a single-frame yield (~33 milliseconds at 30 FPS) to allow stage redraw, ensuring smooth animations (such as rotating a sprite in 10-degree increments across 36 repetitions to complete a full 360-degree rotation). Furthermore, when nesting repeat blocks—such as an outer loop repeating R times enclosing an inner loop repeating C times—the total execution count multiplies combinatorially (R × C total cycles). This deterministic multiplicative iteration forms the computational foundation for generating 2D grid coordinates, procedural tile layouts, and complex algorithmic geometric patterns using the Pen extension.

Easy
A sprite executes the script: [repeat (4): move (10) steps; turn right (90) degrees]. What path does the sprite trace, and how many total steps does it move?
Option A is correct because repeating 4 times a movement of 10 steps followed by a 90-degree right turn traverses the four orthogonal edges of a square (4 × 10 = 40 steps) and completes a 360-degree rotation back to the starting orientation. Option B is incorrect because the 90-degree turns alter heading. Option C is incorrect because a triangle has 3 sides and 120-degree exterior turns. Option D is incorrect because the parameters describe a 4-sided polygon, not a continuous circle.
Medium
Consider a nested loop structure: an outer [repeat (5)] block encloses an inner [repeat (6)] block. Inside the inner loop, a variable “counter” is incremented using [change [counter v] by (2)]. If “counter” starts at 0, what is its final value?
Option A is correct because the inner loop executes 6 times for every single iteration of the outer loop, resulting in 5 × 6 = 30 total executions of the body. Since the counter increments by 2 each time, the final value is 30 × 2 = 60. Option B is incorrect because 30 is the number of loop iterations, not the accumulated value. Option C is incorrect because loop counts multiply rather than add. Option D is incorrect because it reflects only two outer iterations.
Tricky
What is the behavior of the [repeat (n)] block in Scratch 3.0 if the input parameter n evaluates to -5 or 0?
Option A is correct because the Scratch runtime treats any count parameter n <= 0 as a completed iteration condition; the loop body is bypassed with 0 executions, advancing immediately to the block beneath. Option B is incorrect because Scratch does not produce negative counter underflows into infinite loops. Option C is incorrect because Scratch gracefully handles non-positive numbers without errors. Option D is incorrect because [repeat (n)] is a pre-checked loop, not a do-while loop.
Medium

ICSOC-8.11.4.3 Infinite Execution Loops: The Core Game Loop, Thread Scheduling, and Termination

Infinite Execution Loops: The Core Game Loop, Thread Scheduling, and Termination

In real-time interactive game architecture, continuous simulation requires an unbroken operational loop that perpetually interrogates player inputs, updates physics calculations, and coordinates visual rendering. In Scratch 3.0, the “forever” C-block implements this infinite loop paradigm. Distinct from finite loop structures, the forever block lacks an exit notch at its base; once the runtime execution enters the forever loop, instruction pointer advancement never escapes downward out of the block. Instead, upon reaching the terminal nested statement within the loop body, control immediately cycles back to the topmost nested instruction.

Within the Scratch multi-threaded virtual machine, the forever loop operates cooperatively rather than preemptively. To prevent an infinite loop from monopolizing host CPU cores and freezing the web browser, the Scratch runtime automatically injects an execution yield at the end of each iteration whenever visual or motion updates occur, throttling the loop to synchronize with the standard 30 FPS screen refresh rate. The only architectural pathways to break out of an active forever block are external interruptions—specifically via explicit flow termination commands (such as “stop [this script]” or “stop [all]”), triggering a new event under the same hat, or deleting the host sprite clone.

Easy
What distinctive physical structural feature identifies the [forever] C-block in Scratch?
Option A is correct because the [forever] block represents an infinite, non-terminating loop; therefore, it is designed with a flat bottom lacking a connection tab, indicating that no block can ever naturally execute directly below it. Option B is incorrect because oval shapes are reporter blocks. Option C is incorrect because that describes the [if-then-else] block. Option D is incorrect because hat blocks have curved tops, whereas [forever] has a standard top connector notch.
Medium
Why does a script containing [forever: move (10) steps; if on edge, bounce] not freeze the web browser or cause an unresponsive script error?
Option A is correct because the Scratch virtual machine coordinates cooperative multi-threading; loops that contain visual or motion commands automatically yield at the iteration boundary, pacing the loop to synchronize with the standard 30 FPS display refresh cycle. Option B is incorrect because Scratch runs locally in client-side WebGL/JavaScript. Option C is incorrect because modern browsers rely on the engine’s event loop cooperative yielding. Option D is incorrect because the forever loop remains structurally infinite.
Tricky
Which of the following is an effective, valid method to terminate an actively running [forever] loop from within the executing sprite?
Option A is correct because placing [stop [this script]] inside a conditional statement embedded in the forever loop abruptly halts that execution stack, providing a programmatic break mechanism to escape an infinite loop. Option B is incorrect because modifying code manually during runtime is not programmatic algorithm control. Option C is incorrect because the timer cannot be set negative and does not govern forever loops. Option D is incorrect because blocks cannot be placed beneath a forever block due to its flat bottom.
Easy

ICSOC-8.11.4.4 Single-Alternative Selection: Boolean Predicates and Guard Clauses

Single-Alternative Selection: Boolean Predicates and Guard Clauses

Conditional selection represents the core architectural mechanism enabling computer software to exhibit adaptive, dynamic behavior. In Scratch, the single-alternative decision structure is encapsulated by the “if then” C-block. This block features a hexagonal input socket designed specifically to accept boolean reporter blocks—such as relational comparators (<, =, >) and sensing predicates (such as “touching [ ]?” or “key [ ] pressed?”). When program execution arrives at the block, the engine immediately evaluates the embedded boolean expression into a strict binary truth value: true or false.

If the evaluated predicate yields true, the runtime branches into the interior pocket of the C-block, executing all enclosed statements in sequential order before continuing to the subsequent block attached beneath the clasp. Conversely, if the predicate evaluates to false, the runtime completely skips the nested block cluster, advancing directly to the next instruction outside the clasp with zero execution penalty. In competitive Olympiad algorithms and game development, single-alternative “if-then” structures frequently serve as “guard clauses”—preconditional filters positioned inside polling loops to detect discrete game-state transitions, boundary collisions, or critical player thresholds.

Easy
What shape of input socket is present in the [if < > then] block to receive conditional expressions in Scratch?
Option A is correct because hexagonal slots in Scratch are reserved specifically for Boolean blocks (such as comparators and sensing predicates) that evaluate strictly to true or false. Option B is incorrect because rounded slots accept numeric or text reporters. Option C and D are incorrect because Scratch does not utilize rectangular or triangular block sockets for conditions.
Medium
A script contains: [set [score v] to (50); if 40> then: change [score v] by (10); change [score v] by (5)]. What is the final value of “score”?
Option A is correct because the condition 40> evaluates to true (50 > 40), so the inner block executes, adding 10 to score (making it 60). Then, execution proceeds below the if block to the subsequent statement, which adds another 5 to score, resulting in a final total of 65. Option B is incorrect because it omits the outer addition. Option C is incorrect because it assumes the condition was false. Option D is incorrect because it assumes neither block executed.
Tricky
In game programming, an “if-then” statement placed inside a “forever” loop that tests for a boundary touch or health threshold is formally known as:
Option A is correct because in game loop architecture, a conditional branch embedded in the continuous tick loop to verify whether a threshold or event state has been reached is called a guard clause or polling check. Option B is incorrect because polling is synchronous to the loop, whereas interrupts are asynchronous hardware/OS events. Option C is incorrect because Scratch blocks do not manually unwind recursive stacks. Option D is incorrect because Scratch is interpreted at runtime and does not use C-style preprocessor macros.
Medium

ICSOC-8.11.4.5 Dual-Alternative Branching: Mutual Exclusion, Fallback Logic, and Nested Decisions

Dual-Alternative Branching: Mutual Exclusion, Fallback Logic, and Nested Decisions

When an algorithm requires two mutually exclusive execution paths based on a singular decision threshold, the single-alternative structure is insufficient. Scratch addresses this architectural need with the dual-branching “if then … else” block, an E-shaped control structure featuring two distinct internal code pockets separated by an internal divider tab. When execution reaches the block, the embedded boolean condition is evaluated. If the condition resolves to true, the runtime executes the “then” block cluster and strictly bypasses the “else” segment; if false, the “then” cluster is skipped and the “else” cluster executes unconditionally.

A foundational principle of dual branching is strict mutual exclusivity: under no circumstances can both branches execute during a single evaluation pass, nor can both branches be skipped. For multi-way decision trees—such as assigning letter grades based on continuous score ranges—programmers nest additional “if … then … else” blocks directly within the outer “else” pocket, synthesizing the equivalent of “else-if” cascading ladders. Mastering dual branching and nested decision trees enables rigorous handling of edge cases, binary state toggles, and deterministic fallback logic in advanced computational modeling.

Easy
In an [if then … else …] block, what happens if the condition evaluates to false?
Option A is correct because the dual-alternative selection structure enforces mutual exclusivity: when the condition evaluates to true, ‘then’ runs; when it evaluates to false, ‘else’ runs and ‘then’ is bypassed. Option B is incorrect because execution continues through the else branch. Option C is incorrect because the two branches are mutually exclusive. Option D is incorrect because false conditions do not trigger user dialog prompts.
Medium
A project executes: [set [lives v] to (0); if 0> then: say [Keep Playing!] else: say [Game Over!]; change [coins v] by (1)]. Which speech bubble appears, and does [coins] change?
Option A is correct because 0> evaluates to false (0 > 0 is false), so the runtime enters the ‘else’ branch and executes [say [Game Over!]]. Afterward, execution naturally flows out of the C-block into the next sequential instruction, incrementing [coins] by 1. Option B is incorrect because the condition is false. Option C is incorrect because an else pocket does not terminate the script unless an explicit stop block is inside. Option D is incorrect because the else pocket always executes when condition is false.
Tricky
To classify test scores into four distinct rating categories (e.g., Distinction, Merit, Pass, Fail) using only selection structures, how should the blocks be architected?
Option A is correct because creating a multi-tier classification tree requires mutually exclusive categorization; placing nested [if-then-else] structures inside the preceding ‘else’ pockets ensures each category is evaluated sequentially and only one classification branch executes. Option B is incorrect because sequential unlinked if blocks can cause multiple overlapping actions or state overwrites. Option C is incorrect because forever loops do not classify data and prevent script progression. Option D is incorrect because wait until requires a condition and pauses execution rather than branching.
Tricky

ICSOC-8.11.4.6 Condition-Controlled Execution: Pre-Test Loops, Wait-States, and Polling Latency

Condition-Controlled Execution: Pre-Test Loops, Wait-States, and Polling Latency

Condition-controlled structures govern program execution based on dynamically changing states rather than predetermined iteration counts. In Scratch 3.0, this logic is embodied by two complementary control blocks: “wait until ” and “repeat until “. The “wait until” block operates as a synchronous execution barrier or gate: the host script halts and suspends instruction advancement, re-evaluating the boolean condition at every virtual machine tick cycle (~33 ms). Only when the boolean expression transitions to true does the block unblock, permitting the script to advance to subsequent instructions.

Conversely, the “repeat until ” block functions as a condition-controlled pre-test loop. Unlike classic “while” loops in text-based languages (which iterate *while* a condition remains true), the Scratch “repeat until” loop executes its enclosed block body *until* the condition becomes true—meaning it continues looping strictly while the condition evaluates to false. Because the boolean check occurs at the head of each iteration, if the condition is already true prior to loop entry, the enclosed body executes zero times. Olympiad-level developers utilize condition-controlled loops for complex state-driven animations, asynchronous input detection, and autonomous game physics simulation.

Easy
How does the loop termination logic of Scratch’s [repeat until ] differ from a standard “while ” loop found in Python or C++?
Option A is correct because Scratch’s [repeat until] is an inverted pre-test loop: it continues iterating *until* the condition is met (looping while condition == false). In contrast, standard text-based “while” loops continue iterating *while* the condition evaluates to true. Option B is incorrect because repeat until has no fixed iteration count. Option C is incorrect because repeat until accepts any valid boolean reporter. Option D is incorrect because loops do not bifurcate execution threads.
Medium
A script initializes [set [x v] to (10)] and then encounters: [repeat until 5>: change [x v] by (1); move (10) steps]. How many times will the blocks inside this loop execute?
Option A is correct because [repeat until] evaluates the condition prior to executing the loop body (a pre-test loop). Since x is initialized to 10, the condition <10 > 5> evaluates immediately to true upon initial evaluation, causing the runtime to bypass the loop body completely with 0 iterations. Option B is incorrect because the loop body never runs. Option C is incorrect because repeat until is not a post-test (do-while) loop. Option D is incorrect because the exit condition is satisfied immediately.
Tricky
What is the primary operational difference between [wait until ] and a loop structured as [repeat until : wait (0.1) seconds]?
Option A is correct because [wait until] is an internal runtime wait-state that checks the condition on every virtual machine frame tick (~33 ms at 30 FPS) without delay padding. In contrast, enclosing a [wait 0.1 seconds] inside [repeat until] introduces an artificial 100 ms sleep between checks, increasing input latency and potentially missing rapid key presses that occur during the sleep interval. Option B is incorrect because neither block halts other sprites. Option C is incorrect because both blocks can be used by any sprite or the stage. Option D is incorrect because the explicit wait block alters timing resolution.
Tricky

ICSOC-8.11.4.7 Flow Termination: Script Lifecycles, Scope Isolation, and Virtual Machine Halts

Flow Termination: Script Lifecycles, Scope Isolation, and Virtual Machine Halts

Controlled program termination and thread management are governed by the specialized “stop [option v]” block within the Control category. Distinctive in its physical geometry, the stop block possesses a flat bottom notch without an interlocking bottom connector tab (a cap block), signifying that no subsequent blocks can be attached directly beneath it. The block features a dropdown selector offering three distinct termination scopes: “all”, “this script”, and “other scripts in sprite”, each exerting precise control over the Scratch virtual machine’s active thread pool.

Executing “stop [all]” acts as a global kill signal, immediately aborting all running scripts, timers, sound playbacks, and clone lifecycles across all sprites and the stage—mimicking the manual Red Stop Sign button. Selecting “stop [this script]” acts as an immediate return or break statement, abruptly halting only the specific thread stack where the block resides while leaving all other concurrent scripts operational. Lastly, “stop [other scripts in sprite]” provides critical thread isolation: it forcefully terminates every other parallel script running on that specific sprite instance while allowing the currently executing script to maintain uninterrupted control. This prevents race conditions and conflicting state updates during major state transitions, such as health depletion or game-over sequences.

Easy
Which option in the [stop [ v]] block halts every running script, animation, and timer across all sprites and the stage simultaneously?
Option A is correct because the [stop [all]] command acts as a global master halt switch across the entire Scratch virtual machine, terminating all active execution threads, sound playback, and sprite movements, equivalent to clicking the red stop sign. Option B is incorrect because it stops only the single calling thread. Option C is incorrect because it stops only sibling scripts in the host sprite. Option D is incorrect because no such dropdown option exists in Scratch 3.0.
Medium
A sprite has two parallel scripts running under separate [when green flag clicked] hat blocks: Script 1 controls player movement, and Script 2 checks for hazard collision. When Script 2 detects a collision, which block should it execute to stop player movement immediately while allowing Script 2 to continue playing a death animation?
Option A is correct because [stop [other scripts in sprite]] terminates all concurrent sibling scripts running on that specific sprite instance (stopping Script 1’s movement loop) while keeping the calling script (Script 2) active so it can execute subsequent blocks, such as death animations or sound effects. Option B is incorrect because [stop [all]] would terminate both scripts immediately. Option C is incorrect because [stop [this script]] would kill Script 2 while letting Script 1 continue moving. Option D is incorrect because the main sprite is not a clone.
Tricky
Why does the block appearance of [stop [ v]] dynamically change its physical shape depending on which dropdown option is selected?
Option A is correct because Scratch blocks reflect syntax through physical affordances. When “all” or “this script” is selected, the block terminates the active thread, so no code can execute after it, making it a flat-bottom cap block. However, when “other scripts in sprite” is selected, the calling script *continues* running, so Scratch dynamically renders a standard interlocking puzzle notch on the bottom to permit subsequent blocks to be attached beneath it. Option B, C, and D are incorrect because they mischaracterize Scratch’s block geometry and syntax rules.