C++ Decision Making Statements

With C++ decision making statements, easily take decision based on different conditions. The following decision making statemente swe have discussed with examples,

  • if
  • if…else
  • if…else if…else

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 executes 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 programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading