Inconsistent behaviour in loop/until structure

This code:

L = 1
loop
    message "Loop pass No.:  " + str(L)
    L=L+1
until 2

generates two messages - for pass 1 and pass 2. But this code:

L = 1
NumParts = 2
loop
    message "Loop pass No.:  " + str(L)
    L=L+1
until NumParts

generates only the first message. I hesitated to put this up on BitBucket in case it’s just my neurotic iMac. Can somebody please test?

I don’t have time to track down the other posts right now, but this is the way it is designed to work. Formulas, including a simple field or variable, are considered true false values. Zero is false, everything else is true. Since NumParts has a value of 2, it is true, and the condition for ending the loop has been met.

This is not the way Panorama 6 worked, but Jim considers that to be a bug in Pan 6, and contrary to its documentation.

1 Like

In Panorama X I would recommend coding this with a for loop.

for L,1,2
    message ...
endloop

or it could be

for L,1,NumParts
    message ...
endloop

Hello Everybody,
I just read Michael’s question, and Dave/Jim’s response.
I have (in Pan 6) many Loop structures which end in an “until myvariable”, because I don’t know how many loops are needed until something else has first been calculated. How will this be handled in Pan X? The “for …” structure is new to me. Can that be used for an initially unknown variable?

Vic

Yes.

The original code could also be changed to something like this:

L = 1
NumParts = 2
loop
    message "Loop pass No.:  " + str(L)
    L=L+1
until L>NumParts

I would certainly use the for structure if coding from scratch but my current task is importing Panorama 6 files with very large procedures. I’ll just have to locate and fix them.

The simplest fix for me is to replace until variable with until L > variable - but of course that only works where there is a counter, L.

The nice thing about the for statement is that it handles incrementing the counter for you.

Could I suggest that an example of this be added to the Help documentation on Loop statements? It is such a common thing to want to do (for me), and such a change from Panorama 6…