![]() |
| Conditional Decision Making and Branching Statement in C++ |
📑 Table of Contents
▼
Conditional Statements Definition
Conditional Statement in C++: A conditional statement can be using decision making control system. It can be used condition are satisfied or not satisfied. If the given condition are true and given condition are false than return compiler are false. It is very most important in every computer programming languages because conditional statement are handle every situation of condition. Conditional statement are different name is called like Decision making, Condition based, and more. I can explain every topic of conditional statement related simple and easy language.
Types of Decision Making in Management
- If Statement
- If-Else Statement
- Else-If Statement
- Nested If Statement
- Switch Statement
Decision Making With If Statement
If Statement: If the given condition is true than if body will be executed or given condition are false than no if body will be executed. In the case of place if in the place of condition always 0 and non 0 values is checked. Its means condition false and non 0 condition is true. It is called if conditional statement.
Syntax of If Statement in C++
{ Statements; } |
Explain If Statement With Syntax
if(age>=18) { cout<<"Your age is 18 this statement are executed"; } |
Example of If Statement in C++
using namespace std; int main(){ int age; cout<<"Enter Your Age:"; cin>>age; if(age>=18) { cout<<"Your Age 18 You can derive a car"; } } ============OUTPUT============ Enter Your Age:18 Your Age 18 You can derive a car |
If Else Statement in C++
If Else Statement: A if-else statemen can be used two condition are applied if condition are true and if statement/ body will be executed or if condition is false than else statement/body will be executed. It can be most useful statement in every programming language.
Syntax of If Else Statement in C++
{ Statements; } else { Statements; } |
Explain If Else Statement With Syntax
if(age>=17) { cout<<"Your age is 18 this statement are executed"; } else { cout<<"Your age is less than 18 this statement are executed"; } |
Example of If Else Statement in C++
using namespace std; int main(){ int age; cout<<"Enter Your Age:"); cin>>age; if(age>=18) { cout<<"Your Age 18 You can derive a car"; } else { cout<<"Your Age is less 18 you can not derived a car"; } } ============OUTPUT============ Enter Your Age:17 Your Age is less 18 you can not derived a car |
Else If Statement in C++ Definition
Else-If Statement: A else-if statement can be used where multiple condition are applied that use else if statement. It is a part of decision making that execute only one condition at a time. If all condition is false than else part will be execute. If the condition are first condition are true than first statement are executed. if the first condition are false than checked second condition when second condition are true than second statement are executed.
Syntax of Else If Ladder Statement in C++
{ Statements 1; } else if(condition2) { Statement 2; } else if(condition3) { Statement 3; } else { Else Statement } |
Explain Else If Statement With Syntax
if(age>=18) { cout<<"Condition A Execute"; } else if(Condition B) { cout<<"Condition B Execute"; } else if(Condition C) { cout<<"Condition C Execute"; } else { cout<<"if not matched Condition Than Execute Else"; } |
Else If Statement in C++ Example Program
using namespace std; int main(){ int per; cout<<"Enter Your Percentage:"; cin>>per; if(per<=100&&per>=60){ cout<<"You got First Division"; } else if(per<=60 &&per>=50){ cout<<"You got Second Division"; } else if(per<=50 &&per>=33){ cout<<"You got Third Division"; } else{ cout<<"You are Fail..."; } } ============OUTPUT============ Enter Your Percentage:61 You got First Division |
Nested If Statement in C++
Nested If Statement: A nested statement can be used one inside if to another if that is called nested if statement. In the case if if in the place of condition always 0 and non 0 value is checked in which 0 means condition is false and non 0 means condition is true.
Syntax of Nested If Statement in C++
{ if(condition 2) { Statements; } } |
Explain Nested If Statement With Syntax
if(x>=y) { if(x<=y){ cout<<"This statement Executed"; } } |
Nested If Statement in C++ Example Program
using namespace std; int main(){ int x=10; if(x>5){ if(x<15){ cout<<"x is greater than 5 and less than 15"; } } } ============OUTPUT============ x is greater than 5 and less than 15 |
Switch Statement in C++
Switch Statement: A switch statement is allows us to execute one statement from many statement and that statements are called case. Switch statement inside the body of switch a number of cases are used and a parameter are passed. If parameter number is matched the any cases than statement are executed. If the parameter number are not matched than default case are executed.
Syntax of Switch Statement in C++
{ case 1: statement 1; break; case 2: statement 2; break; case 3: statement 3; break; default: default Statement; } |
Explain Switch Statement With Syntax
switch(2) { case 1: cout<<"Case 1 executed"; break; case 2: cout<<"Case 2 executed"; break; case 3: cout<<"Case 3 executed"; break; default: cout<<"Case are not matched"; } |
Switch Statement in C++ Example Program
using namespace std; int main(){ int n; cout<<"Enter any Number:"; cin>>n; switch(n) { case 1: cout<<"Case 1 executed"; break; case 2: cout<<"Case 2 executed"; break; case 3: cout<<"Case 3 executed"; break; default: cout<<"Case are not Matched"; } } ============OUTPUT============ Enter any Number:3 Case 3 executed |
Conclusion of Conditional Statement in C++
Conclusion: This is all about conditional statement it is very most important features of every programming languages. It can be used condition creaking true and false. I can explain every topic in this article if your any question or query you can contact me by email or comments. I can provide solution simple and easy way.

