• 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

my question inmy program if commented line executed error is coming why?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



(Edited: please use [C0DE][/C0DE] tags to format code text - Barry)
[ June 30, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If u don't put any braces after for loop then only the very next statement is within the for loop.
So compiler says that break is not within loop as loop as already ended.
If u comment the statement then if statement comes within for loop(which contains break) so its no problem here.
[ June 30, 2004: Message edited by: Anshul Kayastha ]
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
punctuation
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you uncommment the System.out.println(i); statement, then this the one and only statement that gets executed because you did not put a boolean expression that tests for the end of the for loop! So the rest of the code is "unreachable" and that is what the compiler complains about.

Now, if you intended the whole code (after your uncommented statement) to excecute,then you had to enclose everything in {}:

[B]
Shorter code is

[/B]

(Edited to fix tags)
[ June 30, 2004: Message edited by: Barry Gaunt ]
 
Serge Plourde
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forgot: if your intention is to run the loop 5 times, then you should use "i<5".
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic