• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can "continue" be used in a switch statement?

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
good question.Output is
****************
value is 2 value can be 3 followed by value is 5
****************
Hope i am correct
regards,
NM
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
code will not compile cause continue can only be used in do-while, while-do and for-loops.....
cheers
Oliver
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Where is the continue? I dont see it here.
 
Oliver Grass
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
line 7....
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The labelled continue statement can only be used with repitition structures.
Regards
Danish Shaukat
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic