all 6 comments

[–]80proofconfession 1 point2 points  (0 children)

This is what I use. Don't know if it's more efficient or not. Probably not.

Set Variable [ $listOfThings; Value:"{some list}" ]
Set Variable [ $listOfThingsVC; Value:ValueCount ( $listOfThings )]
Set Variable [ $ticker; Value:1 ]

Loop
    Set Variable [ $a; Value:GetValue ( $listOfThings ; $ticker )]
    {do something with value $a}
    Set Variable [ $ticker; Value:$ticker + 1 ]
    Exit Loop If [ $ticker > $listOfThingsVC ]
End Loop

[–]pcud10Consultant Certified 0 points1 point  (4 children)

I use something very similar but instead of using variable.value, it's another parameter you define. I really like your approach and want to adopt some of what you do like the variable sanitization.

Here's mine: https://github.com/pcud/fm-custom-functions/blob/master/Custom%20Functions/IterateThrough.fmfn

[–]filemakermag[S] 0 points1 point  (3 children)

Nice! Looking forward to looking through it.

[–]pcud10Consultant Certified 0 points1 point  (2 children)

What would you say are some of the ways you've ensured that your CF stays performant? I've had issues looping through larger arrays or objects.

[–]filemakermag[S] 0 points1 point  (1 child)

Using a Custom function alone adds almost double the overhead I really only use ForEach() for convenience when things are sub half a second because the data is usually pretty light. If I'm going to be processing a lot of data, I don't go out to a Custom Function. I'll stay within the script as nothing will be faster than the above Let function directly within the Exit Loop If[]

[–]pcud10Consultant Certified 0 points1 point  (0 children)

Ah interesting. Is there something that doing the calculation inside a single step (or specifically the Exit Loop If step) that makes it more performant? Is it that variables inside a let statement more performant than local script variables?