CalcIt Commands

FOR(nv, start, end, step=1);
...
...
END;

Loop command. E.g.

FOR(n,1,100,1);
 Print(n);
END;

step parameter can be a negative number for decreasing values of nv. Also can be omitted and 1 is assumed.

NOTE: The FOR acts the same way as an assignment operator as regards the variable it uses (n in our example).

 See also WHILEREPEAT, BREAK, CONTINUE, BREAKALL and the alternative FOR syntax to process exclusively arrays below. 

FOR(arr, curelem=arrce, rv, Ascenting=true);
 ...
 ...
END;

In a language where dynamic arrays are used all the time, very frequently the following code is found almost in a monotonous repetition:

set d=[10,20,30,40,50]; //define an array

for(i,1,size(d));
 s:=d(i);
 
//do something with s or update array element value
end;

So a new syntax is needed to handle exactly this kind of frequent loop in codes. This syntax has to offer speed and convenience.

set d=[10,20,30,40,50]; //define an array

for(d,curelem);
 print(curelem);
 ...
end;

In the above rewrite a much simpler syntax is used. The first FOR parameter (d) is the array variable which its contents has to be processed. The second parameter (curelem) is a variable which points in the current element after every FOR repetition. This variable is of a special kind and can be used to read or write to the current array element.

The curelem is optional. In case this parameter is omitted is generarted automatically an identifier with a name composed by array variable's name and the ce (curent element) suffix. e.g

set d=[10,20,30,40,50]; //define an array

for(d);
 print(dce);
 ...
end;

The third optional FOR parameter (rv) is always a simple variable and always reports the index of the current element. This value is used only to report the current index and do not control the operation of the loop. Its value can be changed (by an assignment for example)  in the body of the loop but will take automatically the next index value at the next repetition.

The fourth optional FOR parameter (Ascenting) controls the way the loop advances its implicit index, ascending (by default) or descending. In either case the index increases or decreases always in steps of one.

Go Back