For loop
Username:  
Password:
  > Home
v User Guide
    > Introduction
    > Hello World
    v Flow Control
       o If-else
       o Switch
       o Foreach loop
       o While loop
       o For loop
    > Function Calls
    > Authentication
    > Database access
    > Content Management
    > Remote Calling
    > Object-Oriented
    > Other Features
> Reference
> Portal Object
> Development Guide


Shortcuts
sys Class
debug Class
Intrinsic Conversions
>> User Guide >> Flow Control >> For loop <=  =>      <  1  >  
For loop

A "for" loop is used mainly in looping through uniformly increasing or decreasing number series.

for (i from 1 to 10) display "She loves me {i|?:@value%2 == 0,not}<br>\n";

 

(Showing off a little at the end, but I believe you get the idea.  If not, please consult the BEE Script User Reference - PDF document under Section "Conversion".)

We can also count down:

for (i from 10 to 1) display "{i}\n";

display "<br>We have a lift off!<br>\n";

 

The default "step" is 1 for increasing sequences and -1 for decreasing ones.  However, you can explicitly specify the "step".

for (i from 3 to 11 step 2) display "{i}\n";

// Output: 3 5 7 9 11

for (i from 3 to 11 step 3) display "{i}\n";

// Output: 3 6 9

for (i from 15 to 8 step -4) display "{i}\n";

// Output: 15 11

for (i from 1 to -5 step -2) display "{i}\n";

// Output: 1 -1 -3 -5

 

The loop variable (i in the above case) runs through the range inclusively.  For example, in the first example above, the last number is 11, the higher range boundary.  In the second "for" above, the last number is 9, because the next number in the sequence would bring the variable to 12, which is beyond the higher range boundary.

If "step" is explicitly specified but in the "wrong" direction, the loop will not be executed.  The following loops will not be executed:

for (i from 1 to 5 step -2) display "{i}\n";

for (i from 7 to 2 step 3) display "{i}\n";

 

 

Previous Page       Next Page

Accsoft Computer Technology Pty Ltd     ABN: 98 065 617 549
PO Box 892, Epping NSW 1710         Level 1, Epping Office Park, 242 Beecroft Rd, Epping NSW 2121, Australia
Tel: Sydney - (02)98691668     National - 1300-881668         Fax: (02)98691866
© Copyright 2003 Accsoft Computer Technology Pty Ltd