# WHAT ARE DECISION CONTROL STATEMENTS?

The decision control statements are the decision making statements that decides the order of execution of statements based on the conditions. In the decision making statements the programmer specify which conditions are to be executed or tested with the statements to be executed if the condition is true or false.

# SOME OF THE DECISION CONTROL STATEMENTS ARE

• if statement
• if-else statement
• nested if statements
• switch statement

Let us discuss all these statements briefly.

# IF STATEMENT

The if statement consists a condition which is followed by one or some of the statements, if the condition is true then the statements will be executed or else not. This statement is the simple and easy decision control statement.

# LET US HAVE A LOOK AT THE SYNTAX:

 1234567 if (condition) { //statements to be executed if condition is true }

# LET US HAVE A LOOK AT THE EXAMPLE:

 123456789101112131415 #includeusing namespace std;int main() { int a = 10; if (a > 20) { cout<<“10 is less than 20”; } cout<<“Out of if block”; }

Output:

Out of if block

# IF – ELSE STATEMENT

In the if-else statement the if statement is followed by the else statement which will execute when the expression is false.

# LET US HAVE A LOOK AT THE SYNTAX:

 1234567891011 if (condition) {    //statement will execute if the condition is true } else {   //statement will execute if the condition is false }

# LET US HAVE A LOOK AT THE EXAMPLE:

 1234567891011121314151617181920212223 #include using namespace std;int main () { int x = 30; //variable declaration // check the condition if( x < 20 ) { cout << “x is less than 20;” << endl; // if condition is true then print the following } else { cout << “a is not less than 20;” << endl; // if condition is false then print the following } cout << “The value of x is : “ << x << endl; return 0; }
Output :
a is not less than 20;
the value of X is : 30

We can have the nested if statements also with else statements comparing the different conditions.

# LET US UNDERSTAND THIS THROUGH AN EXAMPLE:

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 #includeusing namespace std;int main( ) { int x =4, y =6, z=10; cout << “\nThe 3 numbers are:”< y) { if( x > z) { cout << “\nx is greatest“; } else { cout << “\nz is greatest“; } } else { if( y > z) { cout << “\ny is greatest“; } else { cout<<“\nz is greatest“; } } return 0; }
Output:
The 3 numbers are  4               6              10
z is greater

# SWITCH STATEMENT

The switch statement allows the variable to be tested for equality against a list of values. In the switch statement every value is called case and the variable is switched on is checked for each case.

# LET US HAVE A LOOK AT THE EXAMPLE:

 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 #include using namespace std; int main () { char grade = ‘c’; // local variable switch(grade) { case ‘a’ : cout << “Excellent!” << endl; break; case ‘b’ : case ‘c’ : cout << “Well done” << endl; break; case ‘d’ : cout << “You passed” << endl; break; case ‘e’ : cout << “Need Improvement” << endl; break; default : cout << “Invalid grade” << endl; } cout << “Your grade is “ << grade << endl; return 0; }
Output :
Well done.