FOR ( )

Function stats

Average user rating
5.0000
37
278
9999
Support
FileMaker 8.0 +
Date posted
22 October 2010
Last updated
16 March 2011
Version
Recursive function
No

Author Info
 Fabrice

74 functions

Average Rating 4.4

author_avatar



 

Function overview

Prototype

FOR  ( _iterator;   _iterations )


Parameters

_iterator  a string (typically


_iterations  the number of iterations


Description

Tags:  Script   Loop   Logical   Iterator   Dev  

Use in an ExitLoop script step to easily define how many iterations you want to operate.

A script like:

Loop
    Exit Loop [ FOR ( "i" ; 5 )]
    Set Variable [ $result ; $i ]
End Loop
Show Custom Dialog [ $result ]

Will display 5 in a dialog box.

During the Loop run, you can use your iterator in expressions.
For example:
Set Variable [ $list = "a¶b¶c" ]
Loop
    Exit Loop [ FOR ( "i" ; ValueCount ( $list )]
    Set Variable [ $result ; GetValue ( $list ; $i )]
Exit Loop
Show Custom Dialog [ $result ]

Will display "c" in a dialog box.

Examples

Sample input

ExitLoop [ FOR ( "i" ; 5 )]


Sample output

executes 5 iterations of the loop

 

Function code

/*

FOR ( _iterator ; _iterations )

Fabrice Nordmann, 1-more-thing

www.1-more-thing.com




v1.1 Mar 2011
    - bug fix for null values
v1. Oct 2010



Use in an ExitLoop script step to easily define how many iterations you want to operate.



A script like:



Loop

    Exit Loop [ FOR ( "i" ; 5 )]

    Set Variable [ $result ; $i ]

End Loop

Show Custom Dialog [ $result ]



Will display 5 in a dialog box.



During the Loop run, you can use your iterator in expressions.

For example:

Set Variable [ $list = "a¶b¶c" ]

Loop

    Exit Loop [ FOR ( "i" ; ValueCount ( $list )]

    Set Variable [ $result ; GetValue ( $list ; $i )]

Exit Loop

Show Custom Dialog [ $result ]



Will display "c" in a dialog box.



*/

Let ( _iterations = GetAsNumber ( _iterations ) ;

Case ( not _iterations ; 1 ; not IsEmpty ( _iterator );

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

    Case (

        Evaluate ( "$" & _iterator ) <= _iterations ; 0 ;

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

    )

)
)

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

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

    Prototype: FOR( _iterator; _iterations )
    Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
    Last updated: 16 March 2011
    Version: 1.4

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

 

Comments

Genx
01 December 2010



Really handy Fabrice... I always have to think for a good 30 seconds (something I don't like doing too much) before writing my loops (pain!!).

Cheers mate!
  General comment
Mark Johnson
26 April 2012



I Love this script. I use it to loop through a list of values to do something with each one and below is the script step i wrote as a sampe of how i use it with a show dialoge box in place of my performscript.

Set Variable [ $list; Value:List ( PortalTable::RecID ) ]
Set Variable [ $i; Value:1 ]

Loop
Exit Loop If [ FOR ( "iStop" ; ValueCount ( $list ) ) ]
 Set Variable [ $result; Value:GetValue ( $list ; $i ) ] // To get current value in what ever position the $i variable is set to.
 Show Custom Dialog [ Title: "Message"; Message: $result; Buttons: “OK” ] // Only to show what the current value is for testing
Set Variable [ $i; Value:$i + 1 ] // To get next value in $list
End Loop

The Variable $i is just used to loop through the $list and get each value one at a time so you can do something with it however you need to. I've used it and it seems to work great for me so far.
  General comment
Fabrice
26 April 2012



Hi,
thank you for your comment.
Actually, you don't even need another iterator ($i)
Simply :
Set Variable [ $list; Value:List ( PortalTable::RecID ) ]
Set Variable [ $list.count ; valuecount ( $list )] // just a small optimization
Loop
Exit Loop if [ FOR ( "i" , $list.count )]
Set Variable [ $result; Value:GetValue ( $list ; $i ) ]
Show Custom Dialog [ Title: "Message"; Message: $result; Buttons: “OK” ]
End Loop
  General comment

 

 

 

 

 

Top Tags

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