• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

for loops

 
teja nelluri
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi everybody,
i am very confusing about this for loops.
please tell me the output of this.if possibel
please exaplian about what is continue outer,
break,continue.
thanks.
outer: for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) {
continue outer;
}
System.out.println("i = " + i + " j = " + j);
}
}
 
Aru
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Teja,

Lemme try to explain this...
outer: for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) {
continue outer;
}
System.out.println("i = " + i + " j = " + j);
}
}
In this code, When the compiler encounters "continue outer" for the first time, would be when 1= 0 & j = 0. Then instead of continuing the the second loop the control jumps to the first loop to continue processing ... & so on
Thx
Aruna
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic