--------------------------------------------------------------------------
A continue can be placed inside a switch ONLY if the switch is enclosed by a loop.
-------------------------------------------------------------------------
---------------------------------------------------------------
C)keyword continue can never occur in a switch statement
---------------------------------------------------------------
In the following program, switch statement is not enclosed by a loop.
continue statement is placed in a switch block.
class
Test {
public static void main(
String args[])
{
switch(1)
{
case 1: for(int i=1;i<=5;i++)
if(i==2) continue;else System.out.println(i);
{System.out.println("end of switch");}
}//switch
}//main
}//Test
output:
1
3
4
5
end of switch
--------------------------------------
1. which of the following are true for a switch statement?
A]all switch statements must have a default label
B]there must be atleast one label for each code segment
C]keyword continue can never occur
D]no case label may follow a default label
E]char literal can be used
------------------------------------------
E- is true.
(B) Statement in a switch body must have a case label, or it is unreaclable.Hence B is true.
class Test
{
public static void main(String args[])
{
switch(1)
{
case 1:{ for(int i=1;i<=5;i++)
if(i==2) continue;else System.out.println(i);}break;
{System.out.println("end of switch");}
}//switch
}//main
}//Test
Result:
Test.java:10: unreachable statement
{System.out.println("end of switch");}
^
Regards
Naresh