Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Guides   Examples
New in version: 7.1   7.2   7.3   7.4   7.5   8.0   8.1   8.2   8.3   8.4    Statistic  

FM.Loop

Universal function to run a loop with evaluate.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
FM 8.2 Yes Yes Yes Yes Yes

MBS( "FM.Loop"; Variable Name; Start Value; End Value; Step Value; Expression { ; ExitIfExpression } )

Parameters

Parameter Description Example value
Variable Name The name of the variable to use.
Can be with zero, one or zwei $ on the start.
"index"
Start Value The start value of the loop. 1
End Value The end value of the loop. 12
Step Value The number to add on each loop.
Must not be zero.
Can be positive to count forward or negative to count backwards.
1
Expression The expression to evaluate.
Can be in local language of FileMaker Pro or english.
For Server must always be in english.
" MBS(\"Log\"; index) "
ExitIfExpression Optional
The expression to evaluate to check for exit early.
Can be in local language of FileMaker Pro or english.
For Server must always be in english.
"index >= 10"

Result

Returns list of results or error.

Description

Universal function to run a loop with evaluate.
Counts number up/down from start to end value. Evaluates each time the formula with new variable value.

If trace is enabled and plugin writes log entries for each evaluate, things are slower than without tracing. For best performance, do not use trace with this function. e.g. call Trace.Off function.

Examples

Loop to place month names in a PDF table:

MBS("FM.Loop";
/* variable */ "index";
/* start */ 1;
/* end */ 12;
/* step */ 1;
/* formula */
"MBS(\"DynaPDF.Table.SetCellText\"; $table; $rowNum; index; \"center\"; \"center\"; GetValue($months; index))")

Loop with Let for multiple commands

MBS("FM.Loop";
/* variable */ "index";
/* start */ 1;
/* end */ 31;
/* step */ 1;
/* formula */
"Let([$rowNum = MBS(\"DynaPDF.Table.AddRow\"; $table);
r = MBS(\"DynaPDF.Table.SetCellText\"; $table; $rowNum; 0; \"center\"; \"center\"; index)]; r)")

Counts upward from 2 to 24:

MBS("FM.Loop";
/* variable */ "index";
/* start */ 1;
/* end */ 12;
/* step */ 1;
/* formula */
"index*2")

Example result:
2
4
6
8
10
12
14
16
18
20
22
24

Counts downwards from 1.0 to 0.0 in 11 steps:

MBS("FM.Loop";
/* variable */ "index";
/* start */ 10;
/* end */ 0;
/* step */ -1;
/* formula */
"index/10")

Example result:
1
.9
.8
.7
.6
.5
.4
.3
.2
.1
0

Inner and outer loop:

Let( [

$Expression1 = "MBS(\"FM.Loop\"; \"j\"; 1; 3; 1; $Expression2)";
$Expression2 = " $i & \" * \" & j & \" = \" & ($i * j)"
// $i in outer loop must be with $ so it's valid in the inner loop
];

MBS("FM.Loop"; "$i"; 1; 4; 1; $Expression1))

Example result:
1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
3 * 1 = 3
3 * 2 = 6
3 * 3 = 9
4 * 1 = 4
4 * 2 = 8
4 * 3 = 12

With an exit early expression:

MBS("FM.Loop";
/* variable */ "index";
/* start */ 1;
/* end */ 12;
/* step */ 1;
/* formula */
"index*2"; // calculate this
"index >= 10") // exit if index gets big

See also

Created 25th March 2018, last changed 25th July 2018


FM.IsMainThread   -   FM.MainThreadID

Feedback: Report problem or ask question.




Links
MBS FileMaker tutorial videos