Continue Inside Nested loops
Whenever we use a continue statement inside the nested loops it skips the iteration of the innermost loop only. The outer loop remains unaffected.
Example:
C
// C program to show working of continue statement // inside nested for loops #include <stdio.h> int main() { int i = 0; for ( int i = 0; i < 5; i++) { for ( int j = 0; j < 3; j++) { // This inner loop will skip when j==2 if (j==2) { continue ; } printf ( "%d " ,j); } printf ( "\n" ); } return 0; } |
In the above program, the inner loop will be skipped when j will be equal to 2. The outer loop will remain unaffected.
Nested Loops in C with Examples
A nested loop means a loop statement inside another loop statement. That is why nested loops are also called “loop inside loops“. We can define any number of loops inside another loop.