public class TestClass{
public static void main(String[] args){
Fo : for(int i = 0; i< 10; i++){
for (int j = 0; j< 10; j++){
if ( i+ j > 10 ) break fo;
}
System.out.println( "hello");
}
}
}
why hello is printed only twice and breaks out of the loop while i debug this on eclipse and suddenly after i=2 it breaks out of the loop, and j can still go till 9th iteration,
please explain in detail its very confusing?
Last edited by admin on Tue Feb 20, 2018 11:16 pm, edited 2 times in total.
Reason:Please put code inside [code] [/code]
When i is 0 or 1, j can go from 0 to 9 without breaking because i+j cannot be > 10 in these cases. This means hello will be printed once when 1 is 0 and second when i is 1. But when i becomes 2, as soon as j becomes 9, break fo; will be executed breaking the outer loop. Hence, the print statement will not be executed.
If you like our products and services, please help us by posting your review here.
so that means it will print the statement only when J loop will finish all its iterations and if it doesnt then it will break out of the loop and the statement. is it?