• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

breaking from a loop

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys!

Can someone point out whats wrong with my code?



When I run them, the compiler says

1. '.class' expected at line 6
2. int j = 0; not a statement at line 6
3. undefined label: loop at line 10

When I remove the int j statement its fine.... I guess its gotta do something with the initialization and I think Java will not permit initializations following a label. Is that true?

I'd like an explanation on that....


Thanks!!!
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Include the loop in {}

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,

labels have to come immediately before a "block" of code. This block can be a for/while/do loop, or it can be marked by enclosing braces {}
 
reply
    Bookmark Topic Watch Topic
  • New Topic