Home News DOC Class DL Others Cooker
Documents  >  Tutorial  >  While
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 of the while statement is:


while ( Conditional-expression )

...

endwhile


If the conditional expression satisfies the condition, the statement in the while statement is executed from the beginning. If the condition is not met, 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 expressions that can be a conditional expression.


An expression that returns a bool class.

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


If it returns a bool class, the statement in the section will be executed if true.

If it returns a number, the statement in the section will be executed if it is not zero.


The conditional expression is re-evaluated at the beginning of the 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


Since it is used as a conditional expression, 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 and the reserved variable __count is defined.

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

__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 conditional expression. Therefore, if you used a reserved variable in a conditional expression, the reserved variable is the one defined by the current while statement.

Statement

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

endwhile

It 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

Next
Previous
Copyright © Rice All rights reserved.