Decision Making Structures in CPlusPlus

Decision Making Structures in CPlusPlus

Decision making structures are very useful in all the programming languages. They require that the programmer should specify certain conditions. Those conditions must be evaluated and based on the result; if the result is true then certain statements should be executed and if the result is false then certain other statements should be executed.

A very typical and common decision making structure can be as below;

Typical Decision Making Structure

C++ language supports various types of decision making structures. You can find the list below.

  1. Simple if statement
  2. If ………. else statement
  3. Nested if ………… else statement
  4. Else if ladder (statement)
  5. Switch Case statement
  6. Conditional Operator/ Ternary Operator Statement
  7. Goto statement

The 2 first types will be discussed in detail here. You can find others discussed in detail in separate articles on our website.

Simple if statement

The general syntax for a simple if statement is:

When the compiler reaches the (if) keyword in the program, it will check the condition. In case the condition becomes true, the statement inside the curly braces will be executed. Otherwise; the statement outside the curly braces will be executed.

See Also:   Function Overloading in CPlusPlus

Example Program:


Output Simple If Statement

See Also:   Array Data Structure in CPlusPlus

If ………….. else statement

            (else) is a keyword in the syntax of C++ language. It helps the programmer to create another block of statements. (if ………. else) structure is the same as the simple if statement. But when you have a number of statements that have to be executed after the condition is checked, it is suggested to use the (if ………… else) statement. In (if ………… else) structure, you can compact a number of statements to be executed once the condition becomes true or false.

General Syntax for an (if ……… else) statement:

Example Program:


Output If ... else Statement

Feel free to post your comments and ask your questions!

Previous Errors List in Visual Basic 2010 Express Edition
Next PHP Tutorials 6: PHP Operators 2

About author

Bahonar Javid
Bahonar Javid 43 posts

<p>* Computer Application Student<br /> * Co-Founder of<br /> * Love to code and Learn new languages<br /> * Enjoy playing football</p>

View all posts by this author →

You might also like