Subscribe Bookmark RSS Feed

For loop exiting after first iteration

nbk

Community Trekker

Joined:

Sep 8, 2014

Hi,

I have a function that I'm trying to run multiple times inside a loop for each unique value of a variable. Everything works great when I run it outside of the loop, and the loop runs fine when I run it without the function call. Have tried wrapping various parts of it in different Eval's, and while it didn't break anything it didn't help either.

The first iteration runs fine and the result of runBT is correct. If I run runBT("clstr2", 1); and runBT("clstr2", 2); outside of the loop it returns the correct results each time. If I comment out runBT inside the loop it shows i = 1 and then i = 2, iterating through both times as expected. Without it commented out it runs the function correctly once and then exits, "loop ended" is shown after the first iteration without any errors.

clust2vals = associative array(dt:clstr2) << get keys;

n = N Items (clust2vals);

show(n); //n = 2

show(clust2vals[1]); // = 1

show(clust2vals[2]); // = 2

for (i=1, i<=n, i++,

    show(i);

    myab = runBT("clstr2", clust2vals);

    show(myab)

  

);

show("loop ended");

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

My guess is that the runBT function is modifying the i or n variables, which to have global scope. You can avoid that by using local variables in your functions or using namespaces.

2 REPLIES
Solution

My guess is that the runBT function is modifying the i or n variables, which to have global scope. You can avoid that by using local variables in your functions or using namespaces.

nbk

Community Trekker

Joined:

Sep 8, 2014

ya that was it, thank you