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

It controls the loop with indexes.


Table of contents:


Format

fromto

Start and end indexes

Loop procedure

Scope

Reserved variable

Statement

endfromto

Example

Format

The format of the fromto statement is:


fromto ( Start-index, End-index )

...

endfromto


The fromto statement repeats the loop while the index determined by the start and end indexes meets the condition. 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 indexes are expressions that determine the index of the fromto statement. they must be enclosed in parentheses and separated by commas.

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


If the start and end indexes 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 indexes 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 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 indexes 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 indexes. Therefore, if you used a 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 indexes. An exception will occur.

Statement

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

endfromto

It 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

Next
Previous
Copyright © Rice All rights reserved.