Key Concepts

Review core concepts you need to learn to master this subject

if statement in C++

if (a == 10) { // code goes here }

In C++, an if statement is used to test an expression for truth. If the expression evaluates to true then the code within the if statement block is executed.

if statement in C++ programming.

if (a == 10) { // code goes here }

In C++, an if statement is used to evaluate an expression. The code block belonging to if is executed if the expression evaluates to true.

C++ else clause.

if (a == 10) { // code goes here }

In C++, we can add an else clause to an if statement. If the condition evaluates to true, code pertaining to if statement is executed. If the condition evaluates to false, code pertaining to else part is executed.

switch statement in C++.

if (a == 10) { // code goes here }

In C++ programming, a switch statement can be used in place of if, else if, else.

It is used in conjunction with case, and the case which matches is executed. default is executed when no case matches.

else if statement in C++.

if (a == 10) { // code goes here }

In C++, to check for multiple conditions, we can have else if statement(s) in between if and else.

Conditionals & Logic
Lesson 1 of 1
  1. 1

    Every program we’ve seen so far has only had one possible path of execution — they all execute line by line, from top to bottom. And every time you run one of those programs, it gives you the same …

  2. 2

    Before we dive deep into the syntax of the […] statement, let’s do a demo! Here, we have coinflip.cpp program that simulates a coin toss: - 50% of the time, it’s Heads. - 50% of the ti…

  3. 3

    An […] statement is used to test an expression for truth and execute some code based on it. Here’s a simple form of the […] statement: […] If the condition is […] , then the *sta…

  4. 4

    When writing conditional statements, sometimes we need to use different types of operators to compare values. These operators are called relational operators. To have a condition, we need relati…

  5. 5

    We can also add an […] clause to an […] statement to provide code that will only be executed if the condition is […] . Here’s a form of an […] statement that includes an […] clau…

  6. 6

    So what happens if you want more than two possible outcomes? This is where […] comes in! […] […] […] The […] statement always comes after the […] statement and before the…

  7. 7

    Now that we know how […] , […] , […] work, we can write programs that have multiple outcomes. Programs with multiple outcomes are so common that C++ provides a special statement for it……

  8. 8

    Congratulations!  Here are some of the major concepts: - An […] statement checks a condition and will execute a task if that condition evaluates to true. - […] / […] statements make …

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo