What are Conditionals?

Conditionals in Programming refer to the computer following different instructions based on certain conditions. Conditionals are also sometimes called branching and/or selection.

There are many examples of Conditionals in real life.

For example, a car driver arriving at a traffic light will observe the following instructions:

  • If light is green, then keep on driving
  • If light is red, then stop

This is an example of Conditionals because, depending on the condition (traffic light state), different instructions are followed.

In Scratch, the main blocks to use for Conditionals are the if then and if then else blocks. There are also many examples of Conditionals in Scratch programs, as they are an essential Computational Concept.

One example of Conditionals in Scratch, that might be part of a bigger Scratch project, could be blocks that say different messages depending on how many lives a character has left in a video game.


This stack of blocks above could run every time a character loses a life (for example: by falling in water) and the number of lives variable is consequently decreased by 1. When the character has 0 lives left, the message: Game Over! will appear. Otherwise, the message about the number of lives left will appear.


Views
1 Total Views
1 Members Views
0 Public Views
Share on Social Networks
Share Link
Share by mail

Please login to share this webpage by email.