for

Prev Next

Function Names

for

Synopsis

for ( init statement, condition expression, loop statement ) statements;
for ( start statement, condition, next statement ) { statements; }

Description

Repeated execution of statements inside a for-loop. First, the init statement is executed and the condition expression is checked. If this expression returns true, then the statements inside the loop will be executed. The loop statement will be executed afterwards, following checking the condition expression again. If the expression is false, then loop execution has finishe.

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

3

Parameters

No.TypeDescription
1
code
statements
:string
init statement

Will be executed once when the loop begins. Useful to initialize loop counters.

2
code
expression
:string
condition expression

Will be calculated before every loop round. The statements in the loop will be executed if this value is true.

3
code
statements
:string
loop statement

Will be calculated after every loop round and before the condition expression is checked again.

Examples

      for (a[] = 3, a[] < 15, a[]+=2)
      {
          print(a[],' ');
          if (a[]==9) a[]++; // Increment to 10
      }

Output

3 5 7 9 12 14
Try it yourself: Open LIB_Function_for.b4p in B4P_Examples.zip. Decompress before use.

See also

while
until
do

Notes

Do not confuse syntax with C/C++! The 3 parameters are separated with commas and not semicolons. You are allowed to add multiple statements into the 1st and 3rd parameter where these statements are separated with semicolons."