File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

labels - great question from appliedreasoning mock --plz help

 
sarim raza
Ranch Hand
Posts: 232
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class LabelTest {
public static void main(String args[]) {
int j =3;
int y=0;
mainLabel: for (int i =0;i<j;i++) {<br /> if (i>1) continue mainLabel;
y++;
}
mainLabel: for (int i =0; i<y; i++) {>
y--;
}
System.out.println(y);
}

//THE OUTPUT IS 1, HOW ??
I AM CONFUSED ABOUT THE USE OF CONTINUE, WHICH MAINLABEL IS IT CALLING, EXPLAIN THE MECHANISM ?
 
sunilkumar ssuparasmul
Ranch Hand
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please pen down u r question properly .
------------------
"Winners don't do different things
They do things differently"
 
Sivaram Ghorakavi
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From my understanding lables are associated to the immediate loops. So in this case the first mainLabel: is associated to the first for(; loop and the second mainLabel: is associated to the second.
Hope this helps...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic