Write the general syntax for switch statement.
Advertisements
Question
Write the general syntax for switch statement.
Advertisements
Solution
The syntax of a switch statement: switch (expression)
switch(expression)
{
case label1:
statements1;
break;
case label2:
statements2;
break;
case labeln;
statements - N;
break;
default:
statements;
}APPEARS IN
RELATED QUESTIONS
Which conditional statement is used to transfer control from current statement to another statement?
Which statement in switch case is used to exit the statement once the appropriate choice is found?
Which of the following is not a branching statement?
What are the different types of control statement used in JavaScript?
What is meant by conditional statements in JavaScript?
List out the various branching statements in JavaScript?
What is if statement and write its types.
The absence of which statement leads to fall through situation in switch case statement?
Consider the following program segment and select the output of the same when n = 10:
switch(n)
{Case 10: System.out.println(n*2);
case 4: System.out.println(n*4); break;
default : Syslem.out.println(n);
}Rewrite the following code using the if-else statement:
int m = 400;
double cl). = (m>300) ? (m/10.0) * 2:(m/20.0)−2;