• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

labeled break and continue

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
can anybody tell me whether it is legel or not to add label to statments other than loops.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Sachin
It is illegal In java
You can't use label other then loop and only in for, while, switch loop, in java Continue and break are a spicial loop flow control so you can't use it another place.
Outer:
System.out.println("HELLO"); // 1
While(i <10) { }
Above code will give compile time error.
yeah but you can use it in C anc C++ at any where

Himanshu Amin
------------------
"JAVA BANAYE BAVA"
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are wrong Himanshu,
the code will compile OK, try it
but it will give a compile error if you try to use the label any where inside the loop
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well what Himanshu was trying to convey was right but the code does compile Himanshu!! The reason is that it is not illegal to label any statement in the program. However when labels are used in conjunction with break or continue they HAVE to refer to loops and not to any statments in the program. Otherwise a compile time error occurs stating 'undefined label'
[This message has been edited by Ash Rai (edited December 18, 2000).]
[This message has been edited by Ash Rai (edited December 18, 2000).]
 
sachin patel
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all very much....
 
Hemant Patel
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rose
In java You can't use label other then loop
means
(1)valid (Just only in starting of loop )
Outer:
while(i <10 ) {.......}
(2)illegal
Outer :
System.out.println("Helo");
while(i<10) {........}
(3)illegal
while(i<10) {
Outer:
System.out.println("Hello");
i++;
}
------------------
"JAVA BANAYE BAVA"
 
Ash Rai
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sachin,
I just visited the FAQ in JavaRanch. It says that declaration statements cannot be labelled. This was news to me! So you too check it out!
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic