0

Does writing break; in inner loop only comes out of inner loop or both the loops ??

24th Aug 2019, 4:30 PM
Aman Jain
Aman Jain - avatar
3 Réponses
+ 6
Aman Jain , I think break applied to the inner loop will stop it , but the outer loop still remains active.
24th Aug 2019, 4:33 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 5
Try it for yourself: #include <stdio.h> int main() { int i = 1, j; while (i <= 5) { printf("\ni = %d", i); j = 1; while (j <= 5) { j++; printf("\nj = %d", j); if (j == 2) { break; } } i++; } return 0; }
24th Aug 2019, 4:44 PM
Paul
Paul - avatar
+ 3
Break statement only breaks the innermost loop.
24th Aug 2019, 5:21 PM
Seb TheS
Seb TheS - avatar