CONTROL STATEMENTS

These statements are used to control the flow of program by using these statements. We can jump from one statement to another statement in C language. We can have four types of control statements:-

  1. decision making
  2. case control statement or switch statement
  3. looping / iteration statement
  4. jump / branching statement

Decision making

These statements are used when we want to take any decision according to the condition or user requirement. These statements work on a particular condition. These conditions are used by using ‘if’ statement. We can have four types of conditional statements

  1. if
  2. if-else
  3. if – else if
  4. nested if

if

if statement is simple decision making statement, which is used to take any decision when the condition is true.

if (statement)

{

Statement;

}

if (expression / condition)

Statement;

If-else

This statement is used to make decision in C language. If the given condition is true then the cursor will move to the true portion else it will move to the false portion.

if (condition)

{

Statement;

}

else

{

Statement;

}

If else-if

This is another control statement which is used to take any decision according to the given condition. If the condition is true then the cursor will move to the true portion and if the condition is false the cursor will move to the false or else-if portion and then checks another condition. If this condition is true then it will move and run the second true portion and if the condition is false then cursor will move the next portion of if condition which is another else-if or else portion.

if (condition)

{

Statement;

}

else if (condition)

{

Statement;

}

else if (condition)

{

Statement;

}

else

{

Statement;

}