Hi all,
when I use break statement like following it doesn't show any error

String o="":
o = o + 2;
 z:
for(int x = 3; x < 8; x++) {
if(x==4) break;
if(x==6) break z;
o = o + x;

but when I interchange the label(z) position

z:
o = o + 2;
for(int x = 3; x < 8; x++)

I am getting label missing error
can anyone help me
thanks in advance

the z: refers to the for loop, but you can't use it to refer to a single expression like o = o + 2;

here is a link you might find usefull to get to better understand the labels

A label in Java can be used for regular code blocks and IF statements along with their regular usage with looping constructs. So you can have:

something:
if (i == 1) {
  method();
  int j = method2();
  if (j == i) {
    break something;
  }
}

Similarly with blocks:

something: {
  method();
  int j = method2();
  if (j == i) {
    break something;
  }
}

Do keep in mind that "continue" can only be used from within looping constructs considering that's the only place it makes sense.

When running in debug mode, breakpoints, interaction pane can be used to check or modify the state variables, the use of Java statements and expressions. The same design is maintained throughout a simple and stable interface.

When running in debug mode, breakpoints, interaction pane can be used to check or modify the state variables, the use of Java statements and expressions. The same design is maintained throughout a simple and stable interface.

labels are not directly linked to debugging, so what exactly are you talking about?

thanks to all for your answers ..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.