FileMaker developers with a background in common programming languages such as C, C++, Java have been deprived a while function since the creation of FileMaker. With the release of FileMaker 18, the wait is over: developers will now have a new tool in the While function.

In most computer programming languages, the While function, or more generically, the While loop is a statement that will allow code to be executed repeatedly until a boolean condition is no longer true. A While loop can be thought of as a repeating If statement.

The official definition of the new function is that it “repeats logic while the condition is true, then returns the result.”

Parameters

Let’s take a look at the parameters used in the While function.

  • [Initial Variable]
  • Condition
  • [Logic]
  • Result

The condition, logic, and result seem pretty straightforward when paired with the definition. Before each iteration, FileMaker checks to make sure the boolean condition is true. As long as it is, FileMaker will evaluate the statements within [logic].  As soon as the condition no longer evaluates to ‘True,’ FileMaker returns the result.

Initial Variables

Variables defined within the [Initial Variable] parameter will be available and consistent throughout the iteration process. Variables can also be set within logic, but there is a critical difference to note, being that variables in logic will be reevaluated on each iteration.

Developers that are familiar with the Let function will have an easier time understanding how this portion of the new While function operates. Similar to the Let function, variables live within the function, they do not require a preceding ‘$’, and they cease to exist once the function returns the result.

Condition

The condition parameter is where we tell the function when to stop iterating. From the help documentation: “While True, the loop repeats. When False, the loop stops.”  This is inverted from what we typically see in FileMaker. For example, the Exit Loop If script step tells FileMaker to exit the loop when the condition is True. Here, only if our condition is false will the function cease to iterate.

Logic

The logic parameter is where the we define the calculations to be performed on each iteration of the loop. The following picture shows a simple use of a While function. While ‘i’ is less than 11, append ‘i’ to the ‘outcome’ variable, which will later act as the result (a counted list to 10). The logic parameter in this case recursively generates the outcome variable as it increments the i variable to manage the number of iterations.

Result

This is how we set what the result returned after it is done iterating. In many uses of the While function, the result is similar to the example above, where each iteration is critical to reaching a correct end result. FileMaker developers no longer have to rely on custom functions to use recursion.

Set Recursion Limit

Along with the arrival of the While function, is the arrival of a function that it will work with nicely. SetRecursion. Similar to the way the EvaluationError function can only be used in tandem with a call to the Evaulate function, the SetRecursion fuction takes a calculation expression as a parameter.

The SetRecursion function sets the maximum number of iterations for recursion and loops within an expression. By default, the While function and recursive custom functions are both limited to 50,000 iterations. The SetRecursion function allows you to increase or decrease this number. If the maxIterations parameter is exceeded by the expression in the expression parameter, the function will return a ‘?’ The FileMaker 18 documentation uses the following calculation to demonstrate this:

This calculation results in ‘?’ because the While calculation used as a parameter of SetRecursion needs to loop through 10 times to get the result, but the SetRecursion limits it to 5. If the SetRecursion calculation was removed, or changed so that maxIterations is greater than or equal to 10, the While calculation would calculate as usual and return a list of integers from 1 to 10.

FileMaker: the premier Workplace Innovation Platform

In conclusion, these additions to the FileMaker toolbox will make it even easier to get data from your disparate sources into the app built for your business. Developers will be able to save time by no longer needing to develop or find custom functions that suit their recursive needs. It’s these kinds of features that really set FileMaker apart as the premier workplace innovation platform.