1.

What are selection statements? Write the syntax for different types of selection statements.

Answer»

Selection statements are used to execute certain blocks of statements by evaluating the condition.

if(condition)

{

statement 1;

statement 2;

statement n;

}

Syntax of if-else statement

if(condition)

{

statement 1;

....

statement n;

else

{

statement 1;

....

statement n;

}

Syntax of if-else-if (nested) statement

If(expression)

{

statements

}

else if(expression)

{

statements

}

Syntax of switch statement

switch(expression)

{

case constant 1:

statements

break

case constant 2:

statements

break

.

.

default

statements

}



Discussion

No Comment Found

Related InterviewSolutions