Originally posted by mohana konakanchi:
public void add(int a) {
loop: for (int i = 1; i < 3; i++){
for (int j = 1; j < 3; j++) {
if (a == 5) {
break loop;
}
System.out.println(i * j);
}
}
}
Why does above method does not print anything if called with 5 as argument?
There is a labeled outer loop in this code. If the result of comparing the argument a to 5 is true,
break statement immediately causes the flow of control to skip the rest of the code and move to the first line
after the labeled loop. Thus, nothing is printed when the argument equals 5 as SOP statement gets skipped.
[ November 13, 2003: Message edited by: Vad Fogel ]