File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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
good question.Output is
value is 2 value can be 3 followed by value is 5
Hope i am correct

"Knowledge is Power"****************<A HREF="" TARGET=_blank rel="nofollow">THREAD/SCJP RESOURCES</A>
Oliver Grass
Ranch Hand

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

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: '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.
Danish Shaukat
I agree. Here's the link:
subject: can "continue" be used in a switch statement?
jQuery in Action, 3rd edition