Introduction

Computer programs are instructions telling the computer how to process input and deliver output. An important part of programming is telling the computer WHEN to perform a certain task. For this, we use something called conditionals. Conditionals get their name because a certain condition or rule must be met in order for an action to be carried out.

Fortunately, people use conditionals all the time in their daily lives!

Have you ever heard your parents say:

  • “If you clean your room, you can go out with your friends.”

  • “If your homework is done, you can play video games.”

  • “If you do your chores all week, you get your allowance, else you are grounded.”

These are all conditionals! Conditionals follow the format of IF this, THEN that.

IF (condition is met), THEN (action performed)

Try to think of a few conditionals from your own life. Once you’ve gotten the hang of it, add the ELSE portion of a conditional.

IF (condition is met), THEN (action performed), ELSE (different action performed)

Example:

  • IF it is snowing, THEN wear boots, ELSE wear shoes.

The ELSE portion makes sure that a different action is performed in either case. Without the ELSE action, you might end up barefoot!

If-Then workflow