Conditions: if and else

Knowledge Videos

Short animated explainers, organised by subject.

Conditions: if and else

A condition is a true or false question. If runs blocks when it is true, else runs when it is false. A fork in the road, with an umbrella or a hat.

Transcript

A condition is a question that is either true or false. Is it raining? Yes, that is true. Is the cat touching the edge? No, that is false.

An if block runs the blocks inside it only when the condition is true. If it is raining, take an umbrella. If it is not raining, the program skips that step.

Add else for the other case. If it is raining, take an umbrella, else, wear a hat. At the fork, the program takes one road, never both.

Remember: a condition is a true or false question. If runs blocks when it is true, and else runs them when it is false.

More in this series