Categories
How To Guides

Control Instructions in C Language

Control instructions in C language enable the user to specify the order in which different instructions in a program has to be executed by the computer. We can say that control instructions determine the ‘flow of control’ in a program. Control Instructions in C language are of four types.

  • Sequence Control Instructions
  • Selection or Decision Control Instruction
  • Repetition or Loop Control Instructions
  • Case Control Instruction

Sequence Control Instructions

This type of instruction that ensures that the instructions are executed in the same order in which they appear in the program.

Selection or Decision Control Instruction

This type of instructions lets the computer to take a decision to which the instruction is to be executed next.

Repetition or Loop Control Instruction

Loop Control Instruction helps computer to execute group of statements repeatedly (on loop).

Case Control Instruction

Like Decision Control instruction, Case Control instruction allows the PC to take a decision to which the excution needs to be executed next.

In C language a decision control instruction can be implemented

  • the if statement
  • The if-else statement
  • The conditional operators

The if Statement

Like most of the languages, C also uses the keyword if to implement decision control instruction. The general look of this statement is as under.

if ( this condition is true )

execute this statement ;

This statement tells the compiler that what follows is a decision control instruction. The condition which follows the if statement is always enclosed in parentheses. If the statement is true then it is executed and if the statement is not true then it will be executed.

The if-else Statement

This type of statement will execute if a specified condition is true. But if the condition is false another block of code will be executed. For that else statement is used.