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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -