If Statements | myBetabox

If Statements

IF statementsĀ are other powerful tools in the programmerā€™s toolbox. To find them in Scratch, you will need to look in the Control folder.

IF statements are used for logic. First, the statements check IF something isĀ true or falseĀ and then run code based on the result.

Letā€™s make a quick example of a program that will move 2 steps forward and 1 step back.

Try this program out for yourself!

The loop works by first checking to see if our variableĀ StepsĀ is < 2. If the variable is less than 2 then it will move forward and add 1 toĀ Steps. If it isnā€™t less than 2 then it will execute the code in theĀ elseĀ area. This code will move the car backwards and set the number of steps back to 0.