Choose Language Hide Translation Bar

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:

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?
0 Kudos
Super User mpb
Super User

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.
0 Kudos

Re: Are nested loops possible using JSL?


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!
0 Kudos