C++ Decision Making Statements

C++ Decision Making Statements

With C++ decision making statements like if…else, elseif, switch, etc, you can easily take decision based on different conditions.

Note: Learn how to run your first C++ program in Turbo C++. We will be running the following programs in the same way.

if statement

The if decision making statement executes the code, if the condition is true.

Here’s the syntax,

Here’s an example showing if decision making statement,

Here’s the output,

if C++ decision making statements

if…else statement

The if…else decision making statement executes some code if the condition is true and another code if the condition is false. The false condition goes comes under else.

Here’s the syntax,

Here’s an example showing the if…else statement,

Here’s the output,

C++ if else decision making statement

if…elseif…else Statement

The if…elseif…else statement execute code for different conditions. If more than 2 conditions are true, you can use else for the false condition.

Here’s the syntax,

Here’s an example showing the if…elseif…else statement,

Here, myVar = 10, and the else condition gets executed.

Here’s the output,

C++ if elseif else decision making statement

C++ Operators
C++ Loops
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create free tutorials for all.

No Comments

Post A Comment