undeclared label error
I am trying to use a label as an escape from a break statement. It is telling
me that it is undeclared label error. How do I declare a label??
Thanks,
Carey
me that it is undeclared label error. How do I declare a label??
Thanks,
Carey
Comments
The break statement, if executed, immediately terminates the loop.· The continue statement, just moves on
to the next iteration of the loop (in this case, that prevents even numbers from getting to the bottom of the loop).
Unlike C, Java allows you to include a label as the target of a break or continue.· This lets you terminate or
continue nested loops.· For example:
Loop0:
· for (x=1;x<10;x++) {
··· for (y=1;y<20;y++) {
····· .
····· .
····· .
····· if (checkexit()==true) break Loop0;
··· }
· }
Also see page 115/116.
regards peter
I took your code and as written it runs fine. When I tried to insert the label below the break code, that is when
I got the undeclared label error. It has to be aware of the label before using it. Wish they had mentioned that in
the manual.
Again Thanks,
Carey