Conditionals

This section explains how programs can be made to take decisions on their own by a process known as "branching".

Programs power thousands of many different tools in use today, from traffic lights to smartphones and the Internet, from social media applications like TikTok to life-saving equipment like MRIs and laser-assisted surgical equipments.

Branching is a special kind of "control flow" in programs. You can read more about control flow here.

These complex applications need to be to make decisions on their own based on their understanding of certain conditions. For example,

  • a traffic light controller has 3 colours ––red, amber and green –– and needs to decide which colour to display, based on the current traffic conditions

  • an iPhone needs to decide which application to start, based on which button was tapped on the screen

  • the TikTok application needs to decide which video to play, based on the video currently visible to the current user

In this section, we will write a simple traffic controller program.

Last updated