Decision control Statements In C

Introduction:
Decision control statements in C allow a program to make choices and execute specific blocks of code based on conditions. These statements help control the flow of execution depending on whether a condition is true or false. The most commonly used decision control statements in C are if, if-else, nested if, and else-if ladder. They are essential for writing logical and flexible programs that can react to different inputs or situations.

The notes are provided by Study Shades Classes Latur. (KAZI A. S. M.)

Decision control Statements In C

1.If statement in C language

It has a condition in brackets. If the condition is true, the statement block, following if statement is executed. If the condition is false, statement block is not executed. Control is transferred to next instruction.

Syntax: – 
if (condition)
{
 Statement;  //executed only if condition is true.
}

Example:-

2) if-else statement

It has a condition inside if bracket. If the condition is true, the statement block following if statement is executed. If the condition is false, the statement block which following else, is executed.

Syntax:-

if(condition)
{
Executed statement1;
}
else
{
Executed statement2;
}

For example:-

 

3) Nested if-else statement

In this statement, if-else statement is placed inside if statement or else statement or both.

Syntax:-

if (condition)
{
     if (condition)
     Statement;
     else
     Statement;
}
else
{
     if (condition)
     Statement;
      else
     Statement;
}

For example:-

 

4) else-if ladder

The else-if ladder is used when you need to check multiple conditions in a sequence. It allows a program to test several conditions one by one. As soon as one condition is true, the corresponding block is executed, and the rest are skipped.

Syntax:-

if (condition1) {
// code block 1
}
else if (condition2) {
   // code block 2
}

else {
   // default code block
}

For example:-

 

5) Conditional operators

C-language has two conditional operators. These are ? and : They are also called ternary operators because they take three arguments

Syntax:-

condition ? expression1 : expression2;
1.If condition is true, expression1 is executed.
2.If condition is false, expression2 is executed.

For example:-

 

6) Switch case statement

It allows us to make a decision from a number of choices. It is also called switch case default statement.

Syntax:-

switch (expression) {
case value1:
// code to be executed if expression == value1
break;
case value2:
// code to be executed if expression == value2
break;

case value3:
// code to be executed if expression == value3
break;

default:
// code to be executed if none of the above cases match
}


For example:-

Conclusion:
Decision control statements in C, such as if, if-else, else-if ladder, and switch, are essential for making logical decisions in a program. They help control the flow of execution based on conditions, allowing the program to respond dynamically to different inputs. Mastering these statements is key to writing flexible and efficient C programs.

Visit diplomachakhazana.com to read more about C language.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top