DECISION-MAKING STATEMENTS IN C

In this article, we will learn about Decision-making statement in C programming language: Its Syntax and types.

What are Decision-Making Statements in C programming?

Decision-Making Statements in C Programming Language allows you to make the decision based on specific condition to determine the order in which statement has to be executed, or repeat a group of statements till particular conditions are met.

What are conditional statements in C Programming Language ?

Decision-Making Statements are also called Conditional Statements.

DECISION-MAKING STATEMENTS IN C
Flowchart of DECISION-MAKING STATEMENTS IN C

IN C PROGRAMMING LANGUAGE THERE ARE FOLLOWING DECISION-MAKING STATEMENTS:

1. IF STATEMENT

It executes the statement within its body if the stated boolean condition is true.

In if statement, a single statement can be added without inserting curly braces { }

Syntax of If statement

if( expression )
{
 statement 1;//Statement to be executed when the condition is true
}
 statement 2;

2. IF…ELSE STATEMENT

It executes the statement(s) followed by if -statement if the boolean condition is true otherwise it will execute the statement(s) followed by the else statement.

Syntax of If-Else statement

 if( expression )
{
 statement 1;//Statement to be executed when the condition is true
}
else
{
 statement 2;//Statement to be executed when the condition is false
}

3. NESTED IF STATEMENTS

It allows the use of conditional statement(s) inside another conditional statement.

Syntax of Nested If statement

 if( expression )
{
  if( expression1 )
   {
     statement 1;//Statement to be executed when the condition is true 
   }
  else 
   {
     statement 2;Statement to be executed when the condition is false
   }
}
else
{
 statement 3;Statement to be executed when the condition is false
}

4. SWITCH STATEMENT

It allows you to test the variable for equality with respect to the value list.

SYNTAX OF NESTED IF STATEMENT

switch(n) // n is any variable
{ 
case 1: 
statement(s);
break; 
case n: 
statement(s);
break; 
default: 
statement(s);
break; 
}

5. NESTED SWITCH STATEMENTS

It has one switch statement inside another switch statement.

Syntax of Nested If statement

switch(n) 
{
case 1: 	
statement(s);
switch(ch2) 
{
case 1:
statement(s);
break;
case n:
statement(s);
}
break;
case 2:
statement(s);
}

Leave a Reply