I have the following from a DB with 49 weekly columns. I have a procedure that checks each column to find if any are missing. The procedure fails when it gets to WK31. I used the following to check the procedure and noted an error in counter (lxN) vs the column name.
lxN=0 axFld=""
Loop
lxN=lxN+1
axFld= axFld+¶+pattern(lxN,"## ")+info(“fieldname”)
Right
Until lxN=50
The results (truncated for clarity) are:
…
29 Wk29
30 Wk30
31 Wk31
33 Wk32
34 Wk33
35 Wk34
…
Note that the value of lxN jumps from 31 to 33, for no reason. I have tried int( and round( and get the same result.
This is a very weird bug. It seems to happen only if the assignment statement is the first statement after the loop statement. In that case, once every 33 times Panorama jumps back up to the top of the loop after the assignment (it’s not a calculation error, it’s a program flow error). This causes the assignment to run twice. I don’t know why, and I have written this up for further investigation.
I think Gary’s solution of using a for loop is the best solution for now. But I was also able to get it to work simply by adding a NOP statement right after the loop and before the assignment.
It doesn’t have anything to do with the original question, but in Panorama 6 it was common practice to scan an array with a loop incrementing a variable, like this:
let n=1
loop
let element = array(theArray,n,separator)
stoploopif element=""
.... do something
n = n+1
endloop
Since the assignment isn’t the first statement in the loop, this technique doesn’t trigger the bug.
Note: In Panorama X, there’s a much better way to scan an array:
looparray theArray,separator,element
... do something
endloop
Sure, but there is no reason to do it that way. In fact, it will make the loop slower. Better to just put 130 instead of 500 in the for statement if that’s what you want to do, and use endloop at the bottom.