1.

Write the syntax and purpose of switch statement.

Answer»

The switch statement is a multi – way branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression. The switch statement replaces multiple if – else sequence.

The syntax of the switch statement is;

switch(expression

{

case constant 1:

statement(s);

braek;

case constant 2:

statement(s);

braek;

.

.

.

default:

statement(s);

}



Discussion

No Comment Found