Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

java - Break statement inside two while loops

Let's say I have this:

while (a) {
  while (b) {
    if (b == 10) {
      break;
    }
  }
}

Question: Will the break statement take me out of both loops or only from the inner one? Thank you.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In your example break statement will take you out of while(b) loop

while(a) {

   while(b) {

      if(b == 10) {
         break;
      }
   }  
   // break will take you here.
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...