Continue statement

It forcebly continues the loop statement.


Table of contents:


Format

continue

Semicolon

Beginning of loop

Example

Format

The format is:


continue ;


It ends the current loop of the loop statement and executes the next loop.

Statements after the continue statement are ignored, and execution control jumps to the beginning of a nearest loop surrounding the continue statement.

continue

A keyword that indicates that it is a continue statement.

Semicolon

The end of a continue statement is represented by a semicolon.

Beginning of loop

A continue statement returns execution control to the beginning of a loop statement, but its position depends on the type of loop statement.

while statement

while ( Conditional-expression )

...

continue;

...

endwhile


The conditional expression evaluates whether the loop can be executed.

The conditional expression is evaluated every loop. Therefore, the loop resumes from the evaluation of the conditional expression.

each statement

each ( Collection-expression )

...

continue;

...

endeach


The collection expression determines a target collection.

The target is evaluated only once at the beginning. Therefore, the loop resumes from the next statement of the collection expression.

fromto statement

fromto ( Start-index, End-index )

...

continue;

...

endfromto


The start and end indexes determine the start and end values of the loop index.

The start and end indexes are evaluated only once at the beginning, but the current loop index is evaluated every loop. Therefore, the loop resumes from the evaluation of the current loop index.

keepon statement

keepon ( Number-expression )

...

continue;

...

endkeepon


The number expression determines the total number of loop.

The total number is evaluated only once at the beginning, but the number of loops is evaluated per loop. Therefore, the loop is restarted from the number of times evaluation.

Example

1:

class example

2:

open method void someMethod()

3:

keepon(10)

4:

if(__index < 5)

5:

continue;

6:

endif

7:

endkeepon

8:

em

9:

ec

When the someMethod() method is called, it rushes into a keepon loop.

At the beginning of the loop, the number of loops is stored in the reserved variable "__index".


If "__index" is 5 times or less, execution control returns with the continue statement.

From the sixth time onward, execution control returns in due to the "endkeepon".

Copyright © Rice All rights reserved.