Types of Control Statements

Types of Control Statements

Published by: Nuru

Published date: 21 Jun 2021

Types of Control Statements Photo

Types of Control Statements

Types of Control Statements are categorized on the basis of the flow of control through any given functions to be implemented. Some of the notable control statements are explained below.

  • Null Statements

The writing of only a semicolon indicates a null statement. Thus, ‘;’ is a null or an empty statement.

For instance,

;     / *null statement* /

This is quite useful when the syntax of the language needs to specify a statement. But, the logic of the program does not need any statement. We use these statements generally in ‘for’ and ‘while’ looping statements.

 

  • Expression Statements

The expression statements consist of an expression followed by a semicolon. Thus, The execution of an expression statement causes the expression to be evaluated.

a = 3;

c = a + b;

++ i;

Printf (“Area = %f”, area);

  • Compound Statements

Compound Statements are the grouping of statements in which each individual statement ends with a semi-colon. We call the group of statements as a block. Compound statements are enclosed between the pair of braces ( {} ). The opening brace ( { ) signifies the beginning. And, closing brace ( } ) signifies the end of the block.

A compound statement consists of several individual statements that are enclosed within a pair of braces { }. The individual statements may themselves be expression statements, compound statements, or control statements. It provides a capability for embedding statements within other statements. Unlike an expression statement, a compound statement does not end with a semicolon. There is the execution of statements inside the box sequentially.

The general form is,

{

Statement 1;

Statement 2;

……….

……………

}

For instance, let us see a program below.

Types of Control Statements

 

  • Sequence Statements

Sequence Statements simply mean the executing of one instruction after the other. We do this in order for which they occur in the program. In the absence of selection or loops, program statements are executed in the sequence in which they appear in the program.

Thus the Syntax is:

Statement 1;

Statement 2;

………..

………

Statement n;

For instance, let us see the program below.

Types of Control Statements

Types of Control Statements

 

  • Selection Statements

Selection statements are part of decision-making statements. These are within the programming languages. They allow taking alternative actions according to the conditions. Sometimes, there is the execution of steps conditionally. The condition is either true or false. Depending upon the ‘truth’ of the condition there are choosing steps. If the condition is true, there is the execution of a step/set of steps. Otherwise, there is the execution of another step/set of steps. Some of the selection statements are The if statement, The if-else statement, The nested if statement, The if-else if statement, The switch statement.

Types of Control Statements