NIOS Computer Science: Chapter 9 – Control Statements Part 4

Download PDF of This Page (Size: 266K)

Image of Nested if structure

Image of Nested if Structure

Image of Nested if structure

(3) ‘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

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

Diagram shows nested-if-else statement

(4) ‘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;

}