• Post Reply Bookmark Topic Watch Topic
  • New Topic

breaking from a loop  RSS feed

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Include the loop in {}

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • 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 {}
 
Are you okay? You look a little big. Maybe this tiny ad will help:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!