Search code examples
mit-scratch

How to Simulate While Loops in Scratch?


In most programming languages, there is a "while" loop that runs code while a condition is true. However, in Scratch, there is only a "repeat until" loop that repeats until a condition is true. How do I simulate a "while" loop in Scratch?


Solution

  • Say you wanted to use a "while" loop to run while "ConditionA" is true.

    WHILE ConditionA
    Say "hello"

    In Scratch, you can use a "repeat until" loop in this way:

    REPEAT UNTIL NOT ConditionA
    Say "hello"