Keepon statement
It controls a loop with the number of times.
Table of contents:
Format
The format is:
keepon ( Number-expression )
...
endkeepon
The keepon statement repeats the loop for the specified number. The total number of loops is determined by the number expression. After looping, 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 total number of loops.
The expression must returns the int and its value must be greater than or equal to 1.
If the expression is less than or equal to zero, the loop will not be executed.
Loop procedure
♦1: At the beginning of the statement, the total 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 total number of loops will be zero.
♦2: The number of loops is judged. If the loop index and the total number of loops are equal, the execution is moved to the next of the endkeepon.
♦3: 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 loop index starting from zero.
The scope has already been generated when evaluating the number of times. Therefore, if you use the reserved variable in the evaluation, the reserved variable is the one defined by the current keepon statement.
Statement
Statements within a keepon statement are optional. You can place statements as many as you want.
endkeepon
This 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 |