While statement

It controls the loop by a condition.


Table of contents:


Format

while

Conditional expression

Scope

Reserved variable

Statement

endwhile

Example

Format

The format is:


while ( Conditional-expression )

...

endwhile


If the conditional expression meets the condition, the statement in the while statement is executed from the beginning. If does not meet the condition, execution moves to the next of the endwhile.

If the execution reached "continue" or "endwhile", execution moves to the conditional expression and resumes the loop from the evaluating.

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

while

A keyword that indicates that it is a while statement.

Conditional expression

There are two type expressions that can use as a condition.


An expression that returns a bool class.

An expression that returns a number: int, long, and real class.


When it is a bool, the loop is executed if it is true.

When it is a number, the loop is executed if it is not zero.


The conditional expression is re-evaluated per loop. Therefore, the restart position of the while loop is a conditional expression.

If the conditional 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(true);

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

...

endwhile


The entity of the proxy must be a bool class or a number.

Scope

The while 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 while, a scope is generated. Then, reserved variables __count and __index are defined.

They are a variable of the int class and are initialized with the number of loops starting from zero.

They do not cause an overflow. If exceed the maximum value of the int, automatically return to zero.


The scope has already been generated when evaluating the conditional expression. Therefore, if you use a reserved variable in a conditional expression, it is the one defined by the current while statement.

Statement

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

endwhile

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

You can use the abbreviation "ew" instead of "endwhile". Note that "ew" is also a keyword.

Example

1:

class example

2:

open method void someMethod()

3:

while (true)

4:

if (__count > 10)

5:

break;

6:

endif

7:

endwhile

8:

em

9:

ec

Copyright © Rice All rights reserved.