Javid Bahonar

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: [button link=”http://codejow.com/function-overloading-cplusplus/” size=”default” icon=”fa-search” side=”left” target=”” color=”b70900″ textcolor=”ffffff”]Function Overloading in CPlusPlus[/button]

Example Program:


Output Simple If Statement

See Also: [button link=”http://codejow.com/array-data-structure-explanation-c/” size=”default” icon=”fa-th-large” side=”left” target=”” color=”b70900″ textcolor=”ffffff”]Array Data Structure in CPlusPlus[/button]

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!

Javid Bahonar
Bahonar Javid

* Computer Application Student * Co-Founder of www.codejow.com * Love to code and Learn new languages * Enjoy playing football

Related Posts
%d bloggers like this: