
===================================================================

The While statement is used to make the system repeat a statement or set
of statements over and over again. You need to be careful with this
statement. If you are not, you can cause an infinite loop to occur.

%^CYAN%^%^BOLD%^-----< Syntax for simgle statement while loops >-----

%^MAGENTA%^%^BOLD%^while( %^CYAN%^%^BOLD%^<test>%^MAGENTA%^ ) %^CYAN%^%^BOLD%^<statement>%^RESET%^;

The while statement will continually repeat the <statement> until the
test returns a 0. The following sample will demonstrate the concept;

while( present("monster") ) to_object("monster")->remove();

What this line of code would do is keep using to_object() to target
each monster and remove it with the -> operator. Once the present()
efun returns a 0, the while loop will stop and control will flow to
the next part of the object's code.

%^CYAN%^%^BOLD%^%^CYAN%^%^BOLD%^%^CYAN%^%^BOLD%^-----< Syntax for block statement while loops >-----

%^MAGENTA%^%^BOLD%^while( %^CYAN%^%^BOLD%^<test>%^MAGENTA%^ ) {
         %^BLUE%^%^BOLD%^block of code here%^RESET%^ }

The block statement while loops function the same as their single step
brothers but with two exceptions. First, they allow you to run several
lines of code at once. Second, it gives you a chance to interupt the
while loop and pass control back to the next line of code in the object.
Please see the %^CYAN%^%^BOLD%^coding return%^RESET%^, %^CYAN%^%^BOLD%^coding break%^RESET%^ and %^CYAN%^%^BOLD%^coding continue%^RESET%^ files
for information about when and how to leave a while statement without
the <test> returning a 0.

int x=20;

while(x>0) {
       x-=1;
       write("This is pass #"+x); }

This sample defines an int varaible called x and sets its value to 20.
It then proceeds to loop thru the { } set of instructions. Once x is
less than 0, the loop will stop.

int x=20;

while(--x) {
       write("This is pass #"+x); }

I have included this second sample to show a small point about <test>.
You may perform operations upon the variable you are testing with the
while statement. The difference between the samples is that the x is
altered inside of the while's test. If the result returns a 0, the test
stops the while loop.

%^RED%^%^BOLD%^-----< Advanced syntax >------

do {
    %^BLACK%^%^BOLD%^<block of statements>
       } while( %^CYAN%^%^BOLD%^<test>%^RESET%^ );

This is an alternative syntax for the while loop. It makes use of a 
second statement called do. The following is a sample;

int x=1;

do {

x+=1;

} while( x < 20);

write("The value of x is "+x);

The above code declared the x variable and assignes a value of 1 to it.
The "do" statement then executes the block of statements inside the {}s
between do and while. Once the while is reached, the test contained
therein is done. If it is false, the do loop is ran again. If it is
true, the loop terminates.


=======================================================================

Ironman
