What is Decision Making in c Programming

Decision making in C programming language provides an efficient way  to  control the flow of execution of a c program.

Consider a scenario you have to make a decision according to some conditions such as the price of a product or its quality while buying. In the same way, while programming the programmer has to decide which part of the code has to be executed for certain conditions for deciding such conditions we use decision-making statements.

C Decision making structures are essential part of a c program.

C programming provides variety of constructs to make decisions. They are listed below.


If Statement in c Programming

In c programming, If the specified condition is true in the if statement then the code in the if the statement is executed otherwise the code in the if the statement is not executed.

In c programming a simple if statement is used to check one condition.

General format is as follows

 //if statement general form
if ( condition )
{
 //set of codes in if statement
}

“if” is the keyword to use the if statement in c programming.

You cant use string as if condition. But you can compare strings in the condition.

Read completely about if statement in c programming here.


If else Statement in C Programming

In if else statement we can execute if block code if condition is true otherwise else block will be executed.

We can also use this statement if we want some code to be executed if the condition of if statement doesn’t true.

“if”,”else” are the keywords in if else block.

Conditions if statement in if else has same characteristics as simple if statement.

General format of if else statement is as follows

//if else statement general form
if ( condition )
{
 //set of codes in if statement
}
else
{
 //set of codes in if else statement
}

Read completely about if-else statement in c programming here.


Else if ladder in c Programming

In the else-if ladder statement, we can execute if block code if the condition is true otherwise else if block will be checked for true condition. Which if or else if block meets the true condition that will be executed.

We can also use this statement if we have multiple check cases.

“if”,”else” are the keywords in else-if block.

Conditions if statement in if else has same characteristics as simple if statement but way of control is different.

At the end specify else statement such that if none of the conditions met then that else block will be executed.

General format of if else statement is as follows

//if else statement general form
if ( condition )
{
 //set of codes in if statement
}
else if ( condition )
{
 //set of codes in else-if statement
}
else if ( condition )
{
 //set of codes in else-if statement
}
else if ( condition )
{
 //set of codes in else-if statement
}
else if ( condition )
{
 //set of codes in else-if statement
}
else if ( condition )
{
 //set of codes in else-if statement
}
else
{
 //set of codes in else statement
}

Read completely about else-if ladder statement in c programming here.

Read more about switch cases in c programming here.