BookmarkSubscribeRSS Feed
Choose Language Hide Translation Bar
Jaz
Jaz
Frequent Contributor

Script Only Runs Once in a Loop

Hi,

 

The below script loops through files in two lists to check which of them match. If they do, the 'tagger' function is used to manipulate the files. I created this code for a GUI in which to test its functionality I chose four files (two for lf and two for lg). The probem is that when the condition is evaluated to true, the 'tagger' script only runs for the first of the matching two files, instead of all four matching files. Was wondering if I was missing something?

commenceTaggingScript2 = Expr(
 For(p = 1, p <= n items(lf), p++,
	For(q = 1, q <= nitems(lg), q++,
		if (Left(lf[p], Length(lf[p]) - 4) ==  Left(lg[q], Length(lg[q]) - 8), print("Sliced Lf: " || Left(lf[p], Length(lf[p]) - 4)); print("Sliced lg: " || Left(lg[q], Length(lg[q]) - 8)); tagger(selectedDirlf || lf[p], selectedDirlg || lg[q]) , print("Not matching"));
); 
); 
); 

 

 

0 Kudos
1 REPLY 1
XanGregg
Staff

Re: Script Only Runs Once in a Loop

Your code worked for me (tried JMP 13 and JMP 14) after adding the following test data:

tagger = function({a, b}, print("tagging", a, b));
lf = {"abc1234", "xyz"};
lg = {"abc12345678", "xyz12345678"};
selectedDirlf = "/LF/";
selectedDirlg = "/LG/";

commenceTaggingScript2;

 

That is, I saw tagger called 2 times out of the 4 comparisons:


"Sliced Lf: abc"
"Sliced lg: abc"
"tagging"
"/LF/abc1234"
"/LG/abc12345678"
"Not matching"
"Not matching"
"Sliced Lf: xyz"
"Sliced lg: xyz"
"tagging"
"/LF/xyz"
"/LG/xyz12345678"

0 Kudos