C Decision Making

Decision Making Statement allows computer to decide block of code to be execute based on the condition.if, if … else,if … else if and switch statements are used as decision making statements in c programming language.

The if Statement

Block of statement executed only when a specified condition is true.

Syntax:

Example:

Above example is valid for single statement in the body of the if statement. If there is a set of multiple statements in the body of the if statement, than it is written inside a pair of parenthesis.

The If…Else Statement

When we want to execute some block of code if a condition is true and another block of code if a condition is false, In such a case we use if….else statement.

Nested If else

When there is an if statement inside another if statement then it is known as nested if else.

 

The if else ladder

The if….elseif…else statement is used to select one of among several blocks of code to be executed.

The Switch Statement

The switch statement is simplified form of the nested if … else if statement , it avoids long blocks of if..elseif..else code.