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 conditionally branches execution to [ label ] until the number of jumps specified by the LOOPCOUNT command has been reached, after which execution falls through to the next line in the script.

 

This function is useful whenever you need to execute a command (or sequence of commands) multiple times.

 

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 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