java - How does position of break; is making a difference in output? -
i working upon program when noticed weird in output behaviour :
getting required output :
while ((str = input.readline()) != null) { if(str.contains("sometext")) { while(str.contains("some_diff_text")==false) { if(str.contains("something")) break; else { //my code; } } break; //difference in output because of break position } } not getting required output :
while ((str = input.readline()) != null) { if(str.contains("sometext")) { while(str.contains("some_diff_text")==false) { if(str.contains("something")) break; else { //my code; } } } break; //not giving me required output } can explain me why there difference in output behaviour ?
in first code snippet, second break inside outer if statement. outer while loop break when outer if condition true.
in second code snippet, second break follows outer if statement. whether or not outer if condition true, outer while loop break.
Comments
Post a Comment