There are a few ways of doing this, but error capture is probably the best one:
Set Error Capture [On]
Go to Record/Request/Page [Next]
If [Get (LastError) ] <> 0
Go to Layout [ "myLayout"]
Set Error Capture [Off]
Seems odd to use error capture for what I think would be a standard database function, but no doubt about it, it works! Thanks!
Takes a bit of time to get used to. You are trying to go to the next record and there is not one so database throws an error. In fact, without error capture on you will see a standard error message whichever way you do it. If it is any easier to digest you can do it the way you suggested before:
If [ Get ( RecordNumber ) = Get ( foundcount ) ]
Will detect the last record in your found set.
in a loop:
Go to record/request/page [next ; exit after last ]
is routinely used to exit the loop.
The first step outside the loop could be your go to layout step.
This would be a lot simpler if the Loop statement had a count parameter, such as "Loop " or "Loop [$count]" that would execute the subsequent statements that number of times and then exit, but in the absence of that count parameter, I'm happy avail myself of the expertise of others (grin). Thanks for your suggestions!
Set Variable [$K ; value: $K + 1 ]
Exit Loop If [ $K > 10 ]
Put whatever code you want executed 10 times here
I like your last solution, PhilModJunk. Very simple and elegant. Also very similar to what I ended up doing, although I have the exit loop at the end of the code, just before the End Loop. Thanks!
The difference from my first and last suggestions lie in what you mean by "selection". If your "selection" is a found set, the Go to record/request/page [next ; exit after last ]
example is simpler.But if you are not looping through the records in a found set, other means to determine when to stop looping must be used.
The Loop, End Loop structure in FileMaker is a generalized loop construct that takes the place of For Next, Repeat until and While loops found in other computer languages. You can reproduce each of the above by where in the loop you place the Exit Loop step (beginning or end of loop). And you can create loops that don't match any of those by putting it somewhere in the middle of the loop.
A key difference between your solution and mine is that putting the Exit Loop step at the beginning of the loop can ensure that the looped code never executes if the exit expression is true right from the start where putting it at the end means that the looped code will always execute at least once no matter how the exit loop instruction evaluates.