Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

FM.Loop

Universal function to run a loop with evaluate.

Component Version macOS Windows Linux Server iOS SDK
FM 8.2 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "FM.Loop"; Variable Name; Start Value; End Value; Step Value; Expression { ; ExitIfExpression } )   More

Parameters

Parameter Description Example Flags
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 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" Optional

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.
Returns empty text if End value is zero and step is positive to allow for 0 time loops.

Similar to the While() function in FileMaker 18.

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

Release notes

  • Version 10.3
    • Fixed an edge case with FM.Loop function where start and end value are zero.
  • Version 8.5
    • Changed FM.Loop to return empty text if you have forward going loop with EndValue 0.
  • Version 8.3
    • Added ExitIfExpression parameter for FM.Loop to early exit.
  • Version 8.2

Example Databases

Blog Entries

This function checks for a license.

Created 25th March 2018, last changed 12nd June 2021


FM.LayoutNames - FM.MainThreadID