Fromto statement

It controls the loop with an index.

Table of contents:



Start and end indexes

Loop procedure


Reserved variable





The format is:

fromto ( Start-index, End-index )



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.


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.



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.


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.


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


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.



class example


open method void someMethod()


message m; // dialog box.


fromto (100, 105)


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


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







Copyright © Rice All rights reserved.