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.

Similar Reads

1. Nested for Loop

Nested for loop refers to any type of loop that is defined inside a ‘for’ loop. Below is the equivalent flow diagram for nested ‘for’ loops:...

2. Nested while Loop

...

3. Nested do-while Loop

A nested while loop refers to any type of loop that is defined inside a ‘while’ loop. Below is the equivalent flow diagram for nested ‘while’ loops:...

Break Inside Nested Loops

...

Continue Inside Nested loops

A nested do-while loop refers to any type of loop that is defined inside a do-while loop. Below is the equivalent flow diagram for nested ‘do-while’ loops:...