ExitLoop ( ExitValue ; LoopLevel ) ( )

Function stats

Average user rating
343
325
9999
Support
FileMaker 7.0 +
Date posted
25 March 2012
Last updated
26 March 2012
Version
Recursive function
No

Author Info
 Arend van Asselt

1 functions

Average Rating None

author_avatar



 

Function overview

Prototype

ExitLoop ( ExitValue ; LoopLevel )  ( ExitValue;   LoopLevel  )


Parameters

ExitValue  The $i value where Exit Loop = 1


LoopLevel   The loop level in a nested loop


Description

Tags:  exit loop exitloopif  

It can be used for a single loop or nested loops. It provides an unique $i value for every nested loop so you can use $i as a parameter in all your expressions in the running script.

By exit $i will be made empty so if you have a loop further on in the script you don't have to set $i in advance.


Examples

Sample input

Loop
Exit Loop If [ ExitLoop ( get ( FoundCount ) ; 1 ) ]
Set Variable [ $list ; $list & GetNthRecord ( Evaluate(Get(LayoutTableName)&"::id") ; $i ) & ]
Loop
Exit Loop If [ ExitLoop ( 3 ; 2 )
Show Dialog [ “Hi I’m number “ & $i ]
End Loop
End Loop


Sample output

A list of ID's from a found recordset with an example that $i has a dedicated value in every nested loop.

 

Function code

Let (
[ $e = If ( $i[LoopLevel+1] = "" ; ExitValue ; $e )
; $i[LoopLevel+1] = Case ( $i[LoopLevel+1] = "" ; 1 ; $i[LoopLevel+1] > $e - 1 ; "" ; $i[LoopLevel+1] + 1 )
; $i = $i[LoopLevel+1]
]
; $i = "" )

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/325

    Prototype: ExitLoop ( ExitValue ; LoopLevel )( ExitValue; LoopLevel )
    Function Author: Arend van Asselt (http://www.fmfunctions.com/mid/343)
    Last updated: 26 March 2012
    Version: 1.5

*/
// ===================================

 

Comments

Fabrice
26 March 2012



Hi,

it seems to me it looks verymuch like For (), but it looks less consuming. http://www.fmfunctions.com/fname/for
I say "it looks", because the code fails to by copied to FM. What is i.Max?
 Bug report
Arend van Asselt
26 March 2012



Hi,

Thanks for your comment! Indeed it contained a bug. The parameter i.Max should be ExitValue. Indeed it looks like For but it has more functionality. I you use nested loops you don't have to worry about the name of the variable containing the iteration value. And it will set the variable in start position at exit loop.
  General comment
Arend van Asselt
26 March 2012



In my attempt finetuning the function to increase speed I deleted a very important step which is needed if you put an expression in ExitValue instead of a fixed number. I apologize for frustrating you if you tried it out without result. The updated version is tested and should work well.
  General comment
Bruce Robertson
26 March 2012



Seems to me it still doesn't work; the levels step on each other.
Shouldn't this work? And if not, why not? You have a level 1 loop (outslde loop) and level 2 loop.

Set Variable[ $outer; 1]
Loop
Exit Loop If [ ExitLoop ( 3 ; 1 ) ]
Loop
Exit Loop If [ ExitLoop ( 3 ; 2 )
Show Dialog [ List("Outer= " & $outer; "Inner= " & $i)]
End Loop
Set Variable[ $outer; 1+ $outer]
End Loop
(Edited by Bruce Robertson on 26/03/12 )
 Bug report
Arend van Asselt
26 March 2012



Somehow the updated function was'nt uploaded right. I asume that I forgot to place a comment so it was aborted (just a beginner on this site :) )
This time the upload was successful!
  General comment
Fabrice
29 March 2012



Very interesting, really.
Thank you!
  General comment
Arend van Asselt
29 March 2012



I also have a more extended version where you can set $i > 1 as a start value and you can count back. The only drawback is that speed decreases lineair by the number of used variables so it's only useful for smaller loops. But if you're curious just let me know and I will publish it!
(Edited by Arend van Asselt on 29/03/12 )
  General comment

 

 

 

 

 

Top Tags

Text Parsing  (31)
Date  (26)
List  (26)
Format  (23)
XML  (22)
Sql  (18)
Dev  (18)
Debug  (15)
Interface  (13)
Text  (13)
Layout  (12)
Variables  (12)
Filter  (10)
Design  (10)
Layout Objects  (8)
Timestamp  (7)