Thursday, July 11, 2019

Flow Control

Flow Control/Decision Making Statement:






The following are some of decision making statement in c langauge.

   1. If 
   2. If Else
   3. Nested if-else
   4. Switch Case



1]. If Statement:

The if statment is used to check some given condition and after based on the result of condition it perfoms the operations.

If statement consists of a Boolean expression followed by one or more statements.

If the Boolean expression evaluates to true, then the block of code inside the 'if' statement will be executed otherwise it execute the code of body.

Syntax Of If Statement:

if(Boolean Expression)
{
//Code you want to be executed;
}



2].If-Else Statement :

 The if-else statement is used to perform two operations for a single condition.if statement can be followed by an optional else statement, which executes when the Boolean expression is false.

We can perform different operations on a single condition like one is for the correctness of the condition and second is for the incorrectness of the condition.


Syntax of If-Else Statement:
 
if(Boolean-Expression)
      {
 //Statement to be executed if condition becomes true;
       }
else
{
//Statement to be executed if condition becomes false;
}

3]Nested if-else Statement:

It is used when there are multiple cases to be performed for different conditions.Nested if-else statement is used when you want to use more then on if-else statement in your program for single operation.

In nested if-else statement if a condition is true then it will execute the statement which is define inside if block, if condition becomes false then it checks the else if condition.if none of the condition is true the else block will be executed.

Syntax Of Nested If else:

if(condition1)
{
//code to be executed if condition1 is true
}
else if(condition2)
{
//code to be executed if condition2 is true
}
else if(condition 3)
{
//code to be executed if condition2 is true
}
else
{
//code to be execured if none of the condition are true .
}
 
 4]Switch Case:

The Switchcase is alternate of the nested if-else statement.Switch case statements are alternative for long if statements that compare a variable to specific integral values.

It provides an easy way to perfom execution to different parts of code based on the value of the expression.Switch is a control statement that allows a value to change control of execution.

   
We can define various statements in the multiple cases for the different values of a single variable.

 Syntax Of Switch Case:

    switch(expression)
    {
    case(1): expresiion:
    //Statement to be execute;
     break;
    case(2) : expression:
    //Statement to be execute;
    break;
    default:
//Message OF invalid choice;
      }


EmoticonEmoticon