Loop Until Ignores Variables

Loops set to loop until the value of a variable don’t loop.

FileGlobal fgCount
fgCount = 3

Loop
Message “X”
until fgCount

Loop
Message “Y”
until 3

The Help file for until states it can only be used with a single integer constant when used to specify the number of loops. If you want to use a variable you would have to go with the for statement instead of the loop.

for fgCount,1,fgCount
    Message “X”
endloop

I don’t get the same meaning out of the Help on that one, and I’m inclined to believe it’s a minor bug. Especially since it’s valid in Panorama 6. But there are a number of ways to make it work in PanX including the way you’ve noted.

Valid point. It should preferably be corrected to comply with the action in Panorama 6 or, at the least, the change should be noted in the Help file.

Gary is reading the help topic the way I intended. The help file says that it must be a constant number with no calculations. A variable is not a constant number. I suppose the text could be modified to specifically mention that variables are not allowed. Ok, I just went to make that change and someone beat me to it! Probably Gary, so thanks!

I am actually quite surprised that this would work in Panorama 6, that wasn’t my recollection. I went back and tested it, and it does in fact work, my recollection was wrong. I think that was actually a bug, which is why I wouldn’t have known. It was not documented to work that way, in fact the Programming Reference wizard shows different code needed to use a variable, like this:

fileglobal fgCount
fgCount = 3
loop
    fgCount=fgCount-1
    ...
until fgCount=0

Let me explain why I think Panorama 6 has a bug and that the way Panorama X works is correct. The way the loop/until was intended to work it would be perfectly valid to write code like this:

let loopOver=false
loop
    ...
    if something
        loopOver=true()
    endif
    ...
until loopOver

But in Panorama 6 apparently this won’t work, because the value of false() is zero and true() is -1 (which is a really huge number when treated as an unsigned number, which it would be here). So in Panorama 6 the loop would either run once (the value is false, which is zero), or the loop would continue millions of times. But it wouldn’t stop when you planned it to.

No, it wasn’t me. :innocent:

Aha – it looks like Thomas Cooper actually submitted this change back in June!