Computer Applications

What is an if-statement ? Give two examples.

Scratch

3 Likes

Answer

The if block from Controls category is used when we have to take an action depending upon a certain condition. It allows a program to execute certain actions only if a specific condition is true. If the condition is false, the actions within the if-statement are skipped.

Consider the following examples:

1. If we want our sprite to move to the center of the stage when it touches the edge of stage, we can use the given script:

if touching edge then
    go to x : 0 y : 0

2. If we want our sprite to say "You win" when it touches another sprite (ball), we can use the given script:

if touching ball then
    say "You win"

Answered By

1 Like


Related Questions