Continue Operator

Overview

The continue operator transfers control to the beginning of the next iteration of the nearest enclosing loop (while, do-while, or for). Its functionality is the inverse of the break operator.

Syntax

continue;

Behavior

  • When encountered within a loop, continue immediately terminates the current iteration.
  • Execution resumes at the loop's condition check or update expression, proceeding to the next iteration.
  • Usage

  • Useful for skipping specific elements or conditions within a loop without exiting the loop entirely.
  • Example

    // Sum of all nonzero elements
    int func(int array[]) {
      int array_size = ArraySize(array);
      int sum = 0;
      for (int i = 0; i < array_size; i++) {
        if (array[i] == 0) continue; // Skip if element is zero
        sum += array[i];
      }
      return sum;
    }
    

    Related Concepts

  • [Break Operator](/basis/operators/break): Exits the loop entirely.
  • [Loop Operators](/basis/operators): while, do-while, for.