If a loop isn’t written correctly, it can continue running endlessly. If this happens, the only way to stop the loop is to force quit Panorama (sneak peak, another method to prevent this problem will be described below). For example, here is a program that uses a loop to convert every name in the current database database to upper case. The loop starts at the top of the database and works its way to the bottom, which it detects by using the info(“stopped”) function. (By the way, a much better and faster way to perform this task would be to use the formulafill statement, but just play along for the purposes of illustrating an endless loop.)
firstrecord
loop
    Name = upper(Name)
    downrecord
until info("stopped")

But what if we made a mistake, and forgot to include the downrecord statement?

firstrecord
loop
    Name = upper(Name)
until info("stopped")

Now the loop will stay stuck at the top of the database. It will never reach the bottom of the database (unless the database contains only one record), so the loop will never stop. It will run endlessly until you force quit Panorama or reboot the entire computer.

To prevent this problem, you can set up a preference to specify the maximum time that a loop can run. Choose Preferences from the File menu, then click on the Advanced panel. In this panel you can edit the timeout value directly or you can choose from a set of common timeouts from the popup menu. Choose ∞ if you don’t want a timeout, but rather the option to run endlessly forever.

The trick in specifying this value is that you don’t want to make it onerous to wait for if a loop does get locked up, but you don’t want to make the timout length so short that legitimate loops get cut short because the timer expires because they finish their work.

So now lets go back to our endless loop example.

firstrecord
loop
    Name = upper(Name)
until info("stopped")

With the timeout preference set to 30 seconds, this loop will run for 30 seconds and then stop with an error, like this.

:

It’s no longer necessary to force quit or reboot the computer to continue using Panorama after running this program.

Customizing the Timeout Delay (TimeLimit Statement)

In addition to setting up an overall timeout for all procedures, you can also set a custom timeout specifically for an individual procedure. This is done with the timelimit statement. For example the statement timelimit 1200 will set the time limit to 20 minutes, which will allow this loop to continue running even if the database has thousands of records.

timelimit 1200
firstrecord
loop
    Name = upper(Name)
    downrecord
until info("eof")

Twenty minutes is a long time, and you might not really be sure how long a loop like this will take. In a situation like this, it might be better to simply set the time limit to zero, which completely disables the timeout (essentially setting it to infinity). This insures that the loop will run all the way to the bottom, no matter how many records there are. (Of course in that case you need to double check your code to make sure the loop will really finish eventually.)

timelimit 0
firstrecord
loop
    Name = upper(Name)
    downrecord
until info("eof")

Customizing Timeout Response

If a timeout occurs, it is handled like any other error. This means you can trap the error if you wish (see Error Handling) and handle it in some custom manner, for example displaying a custom alert.

timelimit 60
firstrecord
try
    loop
        Name = upper(Name)
        downrecord
    until info("eof")
catch
    message "Your request took too long."
endcatch

Loops vs. Other Slow Code

The timeout feature applies only to loops, including the loop, for, loopwhile, looparray, and loopdataarray statements. It also works with loops constructed with the goto statement.

The timeout does not kick in for slow code in general. For example, suppose you have a large database and sorting by state takes 2 minutes. In that situation, you might think that this program would timeout after the second line.

timeout 20
field State sortup
field City sortupwithin

But this doesn’t happen, because the timeout only applies to loops. In the code above, there is no chance of an endless loop, because there is no loop at all. The program will finish eventually, no matter what. So the timeout limit doesn’t apply.


See Also


History

VersionStatusNotes
10.2NewNew in this version.