Article Groups

# Conditional statements

Decision making is part of our day to day working. In every situation we have to evaluate some conditions and take some actions. Decision making is involved in almost every computer program you write.  All programming languages give you the power to write conditional statements. Conditional statements are written using if-else blocks. You have to check some condition in the if block and see if it is true or false. If the condition is true then the code inside the if block gets executed, if the condition is false then the code inside the else block gets executed.

A typical conditional statement is written like this in almost all programming languages

if ( check some condition here… )  {      // If the condition is true then run this code.  }  else  {      // Otherwise run this code.  }

## Nested if else statements

There are situations where you have to evaluate many if else conditions connected to one another and then make a decision. All programming languages gives you the ability to write nested if else statements. An example of a nested if else statement is

if( condition 1)  {      Run this code if condition 1 is true  }  else if (condition 2)  {      Run this code if condition 2 is true  }  else if (condition 3)  {      Run this code if condition 3 is true  }  else  {      Run this code if none of the above conditions are true  }

Learning to evaluate conditions is one of the very basic steps in programming. Both procedural and object oriented languages give you the ability to write conditional statements in your programs.

### E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization