Loop structure example
Loop, Exit Loop If, and End Loop script steps define a structure that enables script steps to be repeated. Script steps between a Loop and an End Loop are executed continuously, until an Exit Loop If condition or an Exit After Last condition is reached for a Go to Record/Request/Page or Go to Portal step.
Use the Exit Loop If script step to specify a calculation to be evaluated. When the calculation result is not zero, it evaluates to True and the loop ends. When the calculation result is zero, it evaluates to False and the loop continues.
Exit Loop If example
Set Field [Sales::Count = 0]
Loop
Exit Loop If [Sales::Count = 25]
Set Field [Sales::Count; Sales::Count + 1]
Perform Script ["Bonus"]
End Loop
In the above example, the first step points to a field named Count and gives a calculation to be evaluated. (The Loop and End Loop steps define the loop structure. Both steps must be present.)
The Exit Loop If step instructs FileMaker Pro to quit performing the steps inside the loop when the value of Count reaches 25. The Set Field step increases the value of Count by adding 1 every time Set Field is performed. The Perform Script step tells what script to perform (as long as the loop structure was not exited). Once the value of Count is equal to 25, the loop ends and control passes to the next step after the End Loop step (if any).
Exit Loop After Last example
Go to Record/Request/Page [First]
Loop
Set Field [Employees::Salary; Employees::Salary * 1.1]
Go to Record/Request/Page [Next; Exit after last]
End Loop
The first step in the above example goes to the first record in the file. The Loop and End Loop steps define the loop structure. The Set Field step increases the value in the Salary field by 10 percent. The Go to Record/Request/Page step goes to the next record in the file. The loop continues, repeating the Set Field and the Go to Record/Request/Page steps, until the last record is found. Because the Exit after last option was used for the Go to Record/Request/Page step, once the last record is found the loop ends.