File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "can "continue" be used in a switch statement?" Watch "can "continue" be used in a switch statement?" New topic
Author

can "continue" be used in a switch statement?

lucy hu
Ranch Hand

Joined: Aug 21, 2000
Posts: 60
Consider the following code:

1. float f=2.14f;
2. outer: switch( (int)f )
3. {
4. case 2 :switch((int)f)
5. {
6. case 2: System.out.println("value is 2");
7. case 3 : System.out.println("value can be 3");continue outer
8. case 4 : break;
9. }
10. case 5: System.out.println("value is 5");break;
11. case 6: System.out.println("value is 6");break;
12. }

what will be the output:
N Mukherjee
Ranch Hand

Joined: Jun 08, 2000
Posts: 141
Hi,
good question.Output is
****************
value is 2 value can be 3 followed by value is 5
****************
Hope i am correct
regards,
NM


"Knowledge is Power"****************<A HREF="http://www.geocities.com/nityananda_mukherjee" TARGET=_blank rel="nofollow">THREAD/SCJP RESOURCES</A>
Oliver Grass
Ranch Hand

Joined: Nov 02, 2000
Posts: 65
Hi,
code will not compile cause continue can only be used in do-while, while-do and for-loops.....
cheers
Oliver
Bruce Lee
Greenhorn

Joined: Nov 20, 2000
Posts: 10

Where is the continue? I dont see it here.
Oliver Grass
Ranch Hand

Joined: Nov 02, 2000
Posts: 65
line 7....
Serge Plourde
Ranch Hand

Joined: Jun 23, 2000
Posts: 140
As Oliver pointed out, it won't compile. And here is the exact message:

Topic005889.java:12: 'continue' must be in loop.
continue outer;
^

I cut and pasted your code in a file/class named by this topic.
Note, you were missing a ";" at the end of the continue statement.
------------------
Hope this helps.
Have a good day.
[This message has been edited by Serge Plourde (edited November 29, 2000).]
Danish Shaukat
Ranch Hand

Joined: Nov 16, 1999
Posts: 340
The labelled continue statement can only be used with repitition structures.
Regards
Danish Shaukat
 
 
subject: can "continue" be used in a switch statement?
 
Similar Threads
Khalid's Mock exam engine question
Dan Chisholm's question from chapter 5
continue Keyword inside the loop
Switch/Label
Battleships - guys please help me out!