LOOPTO        Conditional branch to label using looping

Top  Previous  Next

Syntax:

LOOPTO

[ label ]

Arguments:

[ label ]

A valid label within the current script file to which execution jumps to unless the specified number of loops have been reached.

Options:

none

 

 

 

The LOOPTO command jumps execution to [ label ] if the counter set by the LOOPCOUNT command is greater than zero. Each jump decrements the LOOPCOUNT counter. When the counter reaches zero, execution falls through to the next line in the script. This function is useful any time that you need to execute a command (or sequence of commands) multiple times.

 

A single LOOPCOUNT counter value is shared by all instances of LOOPTO and LOOPIF that appear in a command script. The LOOPCOUNT command may be called multiple times if necessary to reset the counter.

 

Consider the following example in which the value of the filename variable is displayed three times (for no meaningful reason).

 

LOOPCOUNT 3

SET filename = "test file"

:many_tries

DISPLAY filename

LOOPTO many_tries

:done

 

 

Consider the following example which implements an automatic retry loop.  This example retries a failed download a file up to a maximum of five times:

 

LOOPCOUNT 5 ;; set max number of retries

:download

FTPLOGOFF ;; close any existing remote connection

PAUSE /for=10

FTPLOGON "ftp.mydomain.com" /user="UserID" /pw="secret"

RCVFILE "daily.dat" ;; download this file

IFERROR= $ERROR_SUCCESS GOTO done ;; exit loop on success

LOOPTO download

DASHBOARDMSG "Unable to download file after 5 tries"

:done

FTPLOGOFF

 

 

Note: This command makes your code easier for others to read but you could just as well implement the same behavior using the SETNUM, INC, and IFNUM commands to build a retry loop based on the value of a user-defined numeric variable.

 

 

Related command(s): LOOPCOUNT, LOOPIF, GOTO