Search⌘ K

Introduction to Conditional Statements

Explore how conditional statements like IF, IF-ELSE, and IF-ELSE-IF enable programs to make decisions based on conditions. Learn to use pseudocode and flowcharts to represent and implement decision logic in programming.

The need for conditional statements

Often, we take action based on the circumstances around us. This is called decision making. For instance, if the weather is hot, we might drink a cold beverage like a milkshake, and if the weather is cold, we might choose to drink hot chocolate.

Similarly, we want our computer programs to decide what action to take depending on the result of a condition(s). This is where conditional statements like IF, IF-ELSE, and IF-ELSE-IF come into play.

The IF statement

Suppose we want our program to output ...