While ( )

Function stats

Average user rating
5.0000
57
269
9999
Support
FileMaker 8.0 +
Date posted
10 September 2010
Last updated
13 September 2010
Version
Recursive function
No

Author Info
 Andries Heylen

11 functions

Average Rating 4.9

author_avatar



 

Function overview

Prototype

While  ( _iterator;   _exitCondition )


Parameters

_iterator  The name of the iterator variable (e.g.


_exitCondition  The exit loop condition (e.g $i > 3 )


Description

Tags:  While   Loop   Iterator  

Example usage:


Loop
Exit Loop If [ While ( "i" ; $i + 1 >= 3 ) ]
Show Custom Dialog [ Message: $i; Buttons: “OK”, “Cancel” ]
End Loop

Show Custom Dialog [ Title: "After the loop"; Message: $i; Buttons: “OK”, “Cancel” ]

This will result in showing 4 times the custom dialog box, three times inside the loop (showing 1-2-3), once outside the loop (showing empty dialogbox).

Examples

Sample input

While ( "i" ; $i + 1 >= 3 )


Sample output

Will increment $i untill $i >= 3, it will than return 1 and destroy $i

 

Function code

/* While ( _iterator ; _exitCondition )
by Andries Heylen, BH&A
www.bh-a.com

v.1.0 - Sep 10, 2010
- use this function in Exit Loop If [] script step
- function will create the iterator variable $ and increments it with 1
- when the exit condition is met the iterator variable is destroyed

PITFALL: when using the iterator as exit condition (for example $i > 3); you should send $i + 1 > 3. This is because the iterator is incremented only in the custom function, and you will still send the old value of the iterator when you use it in the exit condition.

*/

Evaluate ( "
    Let (
        $" & _iterator & " = $" & _iterator & " + 1
    ;
        Case ( " & _exitCondition & " ; 1 & Let ( $" & _iterator & " = \"\" ; \"\" ) )

    )"
)//endEvaluate

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

    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/269

    Prototype: While( _iterator; _exitCondition )
    Function Author: Andries Heylen (http://www.fmfunctions.com/mid/57)
    Last updated: 13 September 2010
    Version: 1.2

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

 

Comments

Fabrice
11 September 2010



This is a super cool, super simple function.
I think your documentation should mention the fact that if you want to use your iterator in the exit condition, you should add 1 to it.
While ( "i" ; $i + 1 = 3 )
  General comment
Andries Heylen
11 September 2010



Indeed, you still send the old value of the iterator... so you should indeed add + 1 when using the iterator as an exit condition.

But would be nice if this should not be the case... However I don't see how unless sending "$i >= 3" and evaluate the calc in the custom function...

Updated the documentation!
(Edited by Andries Heylen on 11/09/10 )
  General comment
Fabrice
13 September 2010



Another small issue : the function requires FM 8, not 7, because of variables.
  General comment
Andries Heylen
13 September 2010



thx
  General comment

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (26)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Layout  (15)
Interface  (15)
Text  (14)
Variables  (12)
Filter  (11)
Layout Objects  (11)
Design  (10)
Array  (8)