You can exit from a For loop by using Exit For. The following example searches the Global array names for the name "Fred". If it finds the name, it returns the index of the name in the array. Otherwise it returns -1.
For example, if the names array is:
["Frank", "Helen", "Fred", "Linda"]
Then the formula returns 3.
Global StringVar Array names; //The names array has been initialized and filled //in other formulas Local NumberVar i; Local NumberVar result := -1; //The UBound function returns the size of its array //argument For i := 1 to UBound (names) Do ( If names [i] = "Fred" Then ( result := i; Exit For ) ); result
When considered as an expression, the For loop always returns the Boolean value True. Thus you will almost never want a For loop to be the last expression in a formula, since then the formula will then just display the value True rather than your intended result.