# Recursive function: using List() changes a variable too early

Question asked by Dillik on Apr 22, 2012
Latest reply on Apr 23, 2012 by Dillik

### Summary

Recursive function: using List() changes a variable too early

FileMaker Pro

### Version

FMP 12.0v1 (also 11v4)

OS X 10.6.8

### Description of the issue

This one's puzzling me - I'm not sure why this happens, and I'm not positive I've found the most basic conditions in which the puzzling behavior occurs, but here goes anyway:

When I make a recursive function that makes use of global \$\$variables, if on the last iteration of the function I want to clear out a variable, I find that the variable is cleared too early (at the first iteration) if and only if I use a List() function.  If I instead use a paragraph separator, the clearing occurs as expected.

### Steps to reproduce the problem

Let's imagine a function "Test" that's supposed to produce a list of numbers 1 through 5.  I'll also add "(ended)" to the end so we can see when it terminates.  Try this:

Let ( \$\$C = If ( \$\$C; \$\$C; 1 );
List ( \$\$C;
If ( \$\$C ≥ 5;
Let ( \$\$C = ""; "(ended)" );
Let ( \$\$C = \$\$C + 1; Test )
) // end If
) // end List
) // end Let

I get "(ended)" immediately.  If, on the other hand, I replace that List() function with a paragraph separator, the function terminates where it should ("1¶2¶3¶4¶5¶(ended)").

Let ( \$\$C = If ( \$\$C; \$\$C; 1 );
\$\$C & ¶ &
If ( \$\$C ≥ 5;
Let ( \$\$C = ""; "(ended)" );
Let ( \$\$C = \$\$C + 1; Test )
) // end If
) // end Let

This leads me to conclude something about the List() function is somehow triggering the end-state Let() early, but I have no idea how or why that would happen.  This also happens when I use local \$variables in recursive functions, but that's another level of freakiness because recursive functions leave \$variables persistent even though they're probably not supposed to be.

### Expected result

List() and ¶ shouldn't differ in how they cause a recursive function to handle variables.