What is decision making or conditional statement and it's types with examples in c++?

What is decision making or conditional statement and it's types with examples in c++?

Introduction

Sometimes in programming, we need to run the block of the code if some condition is true and this is achieved by the decision-making statement or conditional statement.

What is a decision-making or conditional statement?

The decision-making statement is the statement in which there is an execution of a group of instructions depending upon the result of a condition.

Types of decision-making Statements

  1. If statement:- The if statement is the most common decision control statement. The condition must be in parentheses. The condition can be a relation or logical expression. The statement block will be executed if the condition is true otherwise it will not.

    Its syntax:-

    If(condition){
    Statement block;

    }

  2. If-else statement:- If the statement is used to execute a single statement or group of statements if the condition is true. It does nothing if the condition is false in many cases, we require to execute several statements if the condition is true and if some other group of statements will execute if the condition is false. this purpose is solved by using an if-else statement.

    Its syntax:-

    If(condition){
    Statement block;

    }

    Else{

    Statement block;

    }

    1. Else if ladder:- Sometimes we need to check the multiple conditions and execute the block of statement for that particular condition if it is true. This is achieved by the else if ladder.

      Multiple else if statements are carried out from top to bottom. Each condition is tested and if it is true only then its corresponding statement is executed.

      Its syntax:-

      If(condition){
      statement block;

      }

      Else if(condition){

      Statement block;

      }

      Else{

      }