Computer Science: Control Statements: Nested if Statement and Switch Statement

Get top class preparation for UGC right from your home: fully solved questions with step-by-step explanation- practice your way to success.

Download PDF of This Page (Size: 184K)

Image of Nested if structure

Image of Nested if Structure

‘Nested if’ Statement

(i) The if block may be nested in another if or else block. This is called nesting of if or else block.

If (condition 1)

{

if (condition 2)

{

Statement (s).

}

}

Image of ‘nested if’ statement image-1

Image of ‘Nested if’ Statement Image-1

(ii)

if (condition 1)

statement1.

else if (condition2)

statement2.

else

statement 3.

Diagram shows nested-if-else statement

Diagram Shows Nested-if-Else Statement

‘Switch’ Statement

The if and if-else statements permit two-way branching whereas switch statement permits multiple branching.

The syntax of switch statement is:

switch (var / expression)

{

case constant1: statement1.

|

|

|

break.

case constant2: statement2.

|

|

|

break.

default: statement3;

}

Developed by: