Home News DOC Class DL Others Cooker
Documents  >  Tutorial  >  Keepon
Keepon statement

It controls a loop with the number of times.


Table of contents:


Format

keepon

Number expression

Loop procedure

Scope

Reserved variable

Statement

endkeepon

Example

Format

The format of the keepon statement is:


keepon ( Number-expression )

...

endkeepon


The keepon statement repeats the loop for the number of times determined by the number expression. After looping the specified number of times, execution moves to the next of the endkeepon.

If the execution reached "continue" or "endfromto", execution moves to the first statement of the keepon after updating the loop index.

If the execution reached "break", execution moves to the next of the endkeepon.

keepon

A keyword that indicates that it is a keepon statement.

Number expression

The number expression is an expression for determining the number of loops in a keepon statement.

The number expression is an expression that returns the int and its value must be greater than or equal to 1.


If the number expression is less than or equal to zero, the loop will not be executed.

If the number expression returns a proxy class, the entity of the proxy is automatically used. The result is the same as calling the Entity getter of the proxy class.


proxy pro = new proxy(10);

keepon(pro) // pro.Entity is used.

...

eko


The entity of the proxy must be an int class.

Loop procedure

♦1: At the beginning of the keepon statement, the number of loops is determined from the number expression and the loop index is initialized to zero. This is done only once at the beginning. If the number expression is less than or equal to zero, the number of loops will be zero.


♦2: The number of times is judged. If the loop index and the number of loops are equal, the execution is moved to the next of the endkeepon.


♦3: The statements within the keepon are executed.


♦4: When the execution reaches the "continue" or "endkeepon", the loop index is incremented.


♦5: the execution goes back to the ♦2.

Scope

The keepon statement generates a scope.


Variables declared in the scope are re-declared per loop and new instances are assigned.

It does not carry over the value of the previous loop to the next loop.

Reserved variable

When execution reaches the keepon, a scope is generated and the reserved variables __index and __count are defined.

__index and __count are variables of the int class. It is initialized with the number of loops starting from zero.


The scope has already been generated when evaluating the number of times. Therefore, if you used a reserved variable in the evaluation, the reserved variable is the one defined by the current keepon statement.

Statement

The statements within a keepon statement are optional. You can place statements as many as you want.

endkeepon

It is a keyword that indicates the end of the keepon statement.

You can use the abbreviation "eko" instead of "endkeepon". Note that "eko" is also a keyword.

Example

1:

class example

2:

open method void someMethod()

3:

message m; // dialog box.

4:

keepon (5)

5:

m.Show(__index); // 0, 1, 2, 3, 4

6:

endkeepon

7:

em

8:

ec

Next
Previous
Copyright © Rice All rights reserved.