Continue Statement

The Continue statement gives you the option to skip over the part of a loop where an external condition is triggered, but to go on to complete the rest of the loop iterations. That is, the current iteration of the loop will be disrupted, but the program will return to the top of the loop. The Continue statement will be within the block of code under the Loop statement, usually after a conditional if statement.

The continue statement (in most computer programming languages), takes the generic form of:

WHILE Boolean expression
statement_1
IF Boolean expression THEN
CONTINUE
ENDIF
statement_2
counter = counter + 1
ENDWHILE
FOR counter in range(n)
statement_1
IF Boolean expression THEN
CONTINUE
ENDIF
statement_2
ENDFOR

In this example program, the user is asked to enter a positive integer and the program will count how many times it goes through the loop until it reaches that number, except it will always skip 5!

Top-Down Design for the Continue Statement

Top-Down Design for Continue Statement

Flowchart for the Continue Statement

Continue Statement flowchart

Pseudocode for the Continue Statement

GET positive_integer
WHILE (counter < positive_integer)
counter = counter - 1
IF (counter + 1 == 5) THEN
CONTINUE
ENDIF
SHOW counter + 1
ENDFOR

Code for the Continue Statement

 1// Copyright (c) 2020 Mr. Coxall All rights reserved.
 2//
 3// Created by: Mr. Coxall
 4// Created on: Sep 2020
 5// This program uses a for loop
 6
 7#include <stdio.h>
 8
 9int main() {
10    // this function uses a for loop
11    int positiveInteger;
12
13    // input
14    printf("Enter how many times to repeat: ");
15    scanf("%d", &positiveInteger);
16    printf("\n");
17
18    // process & output
19    while (positiveInteger >= 0) {
20        // yes, this is the exception on placing the counter at the top
21        // if you did not, then there would be an infinit loop
22
23        positiveInteger--;
24        if (positiveInteger + 1 == 5) {
25            continue;
26        }
27        printf("Current variable value: %d\n", positiveInteger + 1);
28    }
29
30    printf("\nDone.\n");
31    return 0;
32}

Example Output

Code example output