Key Concepts

Review core concepts you need to learn to master this subject

Conditional Statements

int temperature = 60; if (temperature < 65) { std::cout << "Too cold!"; } else if (temperature > 75) { std::cout << "Too hot!"; } else // brackets may be omitted here std::cout << "Just right...";

Conditional statements are used to control the flow of code execution by testing for a condition for truth.

  • if statements execute code only if the provided condition is true.
  • else statements execute code only if the provided condition in the if statement is false.
  • one or more else if statements can be added in between the if and else to provide additional condition(s) to check.

Some useful tricks with conditional statements:

  • It is possible to condense an if-else expression into a single statement using the following syntax:
    variable = (condition) ? condition_is_true : condition_is_false;
  • Curly brackets { } may be omitted if there is only a single statement inside a conditional statement.

What you'll create

Portfolio projects that showcase your new skills

Pro Logo