Fromto statement

It controls the loop with an index.


Table of contents:


Format

fromto

Start and end indexes

Loop procedure

Scope

Reserved variable

Statement

endfromto

Example

Format

The format is:


fromto ( Start-index, End-index )

...

endfromto


The fromto statement repeats the loop while the index meets the condition. The condition is determined with the start and end index. When the index no longer meets the condition, execution moves to the next of the endfromto.

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

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

fromto

A keyword that indicates that it is a fromto statement.

Start and end indexes

The start and end index are expressions that determine the index. they must be enclosed in parentheses and separated by a comma.

They must be an expression that return the int. Both are evaluated only once before the first loop and their values do not change during the loop.


If the start and end index are equal, the loop will not be executed.

If the start and end values return 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(0);

fromto(pro, 10) // pro.Entity is used.

...

eft


The entity of the proxy must be an int class.

Loop procedure

♦1: The start and end index are evaluated at the beginning of the fromto and the loop index is initialized to the start value. This is done only once at the beginning.


♦2: The condition is judged. If the loop index and the end index are equal, the execution is moved to the next of the endfromto.


♦3: Statements within the fromto are executed.


♦4: When the execution reaches the "continue" or "endfromto", the loop index is incremented or decremented as follows.


Start < End: the loop index is incremented.

Start > End: the loop index is decremented.


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

Scope

The fromto 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 to the fromto, a scope is generated and the reserved variable __count is defined and __index is declared.

__count is a variable of the int class. It is initialized with the number of loops starting from zero.

__index is a variable of the int class. It is initialized with the current loop index after the start and end index have been evaluated.

__count does not cause an overflow. If __count exceeds the maximum value of the int, it returns to zero.


The scope has already been generated when evaluating the start and end index. Therefore, if you use the reserved variable in these evaluation, the reserved variable is the one defined by the current fromto statement.

Please don't use __index for start and end index. An exception will occur.

Statement

Statements within a fromto statement are optional. You can place statements as many as you want.

endfromto

This is a keyword that indicates the end of the fromto statement.

You can use the abbreviation "eft" instead of "endfromto". Note that "eft" is also a keyword.

Example

1:

class example

2:

open method void someMethod()

3:

message m; // dialog box.

4:

fromto (100, 105)

5:

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

6:

m.Show(__index); // 100, 101, 102, 103, 104

7:

endfromto

8:

em

9:

ec

Copyright © Rice All rights reserved.