BookmarkSubscribeRSS Feed

Are nested loops possible using JSL?

Is there a way to script a nested loop statement using JSL? I'm running into errors when I try. I am writing a script that transforms a dataset using indirect lognormal correction for change of support and I think I need a nested WHILE statement to make it work.

Although I realize the syntax is not entirely correct, the following illustration conveys what I am trying to do:

i=1;
j=1;
n=NRow() // with more than 209,000 rows

While( i < n-1,
While( j < n,
s = s + ( data(i) * data(j),
j = j++),
i = i++);

There is always more than one way to accomplish things, so if JSL does not support nested loops does anyone have any suggestions?
2 REPLIES
mpb

Super User

Joined:

Jun 23, 2011

Re: Are nested loops possible using JSL?

Sure you can nest loops. Here's a very simple example using nested "for" loops. Look in the log for the results.

Re: Are nested loops possible using JSL?

mpb,

You are absolutely correct. Your script works just as it should. The problem with my script turned out to be a bit of code preceding the loop where I tried reusing a variable and it wasn't overwriting the original value the way I thought it would.

Thanks for your help!