Skip to main content
Informatik.uz
Chapter 2. Programming in Scratch

Conditions in Scratch

The “if” block and comparison operators let a program make decisions. We check whether a sprite touches an edge and build a simple logical decision.

Topic 9 of 111 min readUpdated October 27, 2026
All topics (9 of 11)

To make decisions in Scratch we use the “if ... then” block from the Control category. The blocks inside it run only when the condition is true. The “if ... then ... else” block runs other commands when the condition is false.

A condition is built from hexagonal blocks in the Sensing and Operators categories. For example, the “touching ...?” block checks whether a sprite touches another sprite or a colour, and the “>”, “<” and “=” blocks compare numbers. Several conditions are joined by the “and”, “or” and “not” blocks.

An example: let the cat turn back when it reaches the edge of the stage. After a “when green flag clicked” block, put “move 10 steps” and “if touching edge? then turn 180 degrees” inside a “forever” block. A small fix: to stop the cat from flipping upside down, set the rotation style to “left-right”.

Another example: if the sprite touches the colour red, it says “You lose!”. The script keeps checking the condition inside the “forever” loop. If the condition is checked only once, the event might be missed, so the check must go inside the loop.

Key takeaways

  • Commands inside an “if” block run when the condition is true.
  • The “if ... else” block gives two paths.
  • A condition is built from sensing and operator blocks.
  • The condition should be checked inside a “forever” loop.

Practice tasks

  1. Build a script in which the cat turns back at the edge of the stage.
  2. Write a script in which a sprite changes colour when the mouse pointer touches it.
  3. Build a script in which two sprites say “We crashed!” and stop when they touch.

Review questions

Test yourself: think first, then reveal the answer.

  1. 1When does an “if” block run the commands inside it?
    Only when the condition is true.
  2. 2Why should the condition go inside a loop?
    So the program keeps checking it and does not miss the event.

0 of 11 topics completed

Sign in to mark
Informatika 6-sinf darsligi muqovasi
In the textbookInformatics — Grade 6