If I have if() statements nested in a for() loop, does a break; within them apply to the for() loop? [duplicate]

StackOverflow https://stackoverflow.com/questions/23176935

  •  06-07-2023
  •  | 
  •  

سؤال

Nothing to add beyond the question provided in the title...

Example:

for(...) {
     if(...) {
         if(...) {
             //doing stuffs
             break;
         }
     }
}

//does that break statement get me to this spot?
هل كانت مفيدة؟

المحلول

In that case, it will break out of the for loop. break will break from loops (such as while, do/while, for) and switch statements.

نصائح أخرى

Yes. The break will break out of the for-loop. break doesn't break out of if-statements.

Yes. Because break doesn't work for if statements. Therefore, it will work for the next loop encountered.

Note: break is used to terminate loops (for, while, or do-while).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top