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 |
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
- Added FM.Loop function.
Example Databases
Blog Entries
- Query current found set with Execute FileMaker Data API as JSON
- Sending email with a huge custom function
- MBS FileMaker Plugin, version 10.3pr6
- Fun with While function in FileMaker
- FileMaker Roadmap for 2019
- MBS FileMaker Plugin, version 8.5pr3
- Using found set in SQL queries
- MBS FileMaker Plugin 8.2 - More than 5200 Functions In One Plugin
- Sum up values in JSON with MBS FileMaker Plugin
- New FM.Loop function
FileMaker Magazin
This function checks for a license.
Created 25th March 2018, last changed 12nd June 2021