Project

General

Profile

Up

forI

ForI is a for-like.

Prototype :

fun [fun [I] u0 I fun [I u1] I u1 I] I

  • fun [I] u0 : function to call to each item
  • I : the initial value
  • fun [I u1] I : condition. If this function returns 1, the loop continue, otherwise, the loop ends
  • u1 : user_parameter (for the condition)
  • I : step

Return : I 0 if no error occurs during the loop, else nil

See also :

forList

forTab

Example

In this basic example, the initial value (0) is increased to 2 and fexec is ran if fcondition is true. When fcondition is not true, the loop stops

fun fcondition (item, user_parameter)=
	item < user_parameter;;
	
fun fexec (item)=
	_fooId item;;	// 0 2 4

fun main ()=
	_showconsole;
	forI @fexec 0 @fcondition 5 2;
	0;;

In C, we could do something like that :

int item;
for (item = 0; item < 5; item+=2)	/* initial value (0); fcondition with user_parameter (5); step (2) */
	printf ("%d\n", item);		/* fexec */

Note : if you need more arguments to 'fexec', you can use mkfunX function(s) or use global(s) variable(s).