Statements: continue

The continue statement skips the current iteration of a for, while or do-while loop and continues with the next iteration.

Syntax

continue

Discussion

The continue statement, when executed inside a loop, causes the control to jump to the beginning of the loop for next iteration. Other statements remaining inside the body of loop for the current iteration are skipped over in this case. Loop expressions and the condition associated to the loop are evaluated regularly. Following examples demonstrate the usage of the continue statement:

// Within a 'while' loop
while ( inx++ < count )
{
  var int32 v = Array[ inx ];

  if ( !v )
    continue;

  sum += math_pow( 2, v );
}

// Within a 'do-while' loop
do
{
  var int32 v = Array[ inx ];

  if ( !v )
    continue;

  sum += math_pow( 2, v );
}
while ( inx++ < count );

// Within a 'for' loop
for ( inx = 0; inx < count; inx++ )
{
  var int32 v = Array[ inx ];

  if ( !v )
    continue;

  sum += math_pow( 2, v );
}

In case of nested loops, the continue statement affects the nearest enclosing loop in which it appears. Please note, continue statements are intended to be used within the body of a loop only. The usage of continue outside a loop causes Chora compiler error message.