Loop commands
loop Loop
Repeats the enclosed commands.
Block command: loop … endloop.
Parameters of every variant
| Parameter | Value | Default | Description |
|---|---|---|---|
--measure | true / false | false | Record every round for the performance report: start, end, robot, units, human time against robot time (Administration → Performance) |
--unitcount | number | 1 | Measured rounds: business transactions one round handles (e.g. invoices in the batch) |
--humanseconds | number | Measured rounds: seconds a person needs for one unit of this work | |
--businessunit | text | Measured rounds: business unit to report under (the task's unit when empty) |
Types (--type)
--type:range
| Parameter | Value | Default | Description |
|---|---|---|---|
--from required | number | ||
--to required | number | ||
--step | number | 1 | |
--variable required | variable name | The current number: --from, then --from + --step… up to --to |
--type:times
Runs the enclosed commands a fixed number of times (0 or less: not at all).
| Parameter | Value | Default | Description |
|---|---|---|---|
--times required | number | How many times, e.g. 5 or $count$ | |
--index | variable name | Variable that receives the round's position, starting at 0 (the first item is 0, as in $list[0]$) |
--type:list
| Parameter | Value | Default | Description |
|---|---|---|---|
--list required | $variable$ | ||
--variable required | variable name | ||
--index | variable name | Variable that receives the round's position, starting at 0 (the first item is 0, as in $list[0]$) |
--type:datatable
Runs once per row of a datatable variable (e.g. from capture --action:gettable, database --action:query or csv --action:read).
| Parameter | Value | Default | Description |
|---|---|---|---|
--table required | $variable$ | The datatable variable | |
--variable required | variable name | The current row: $row.Column$ | |
--index | variable name | Variable that receives the round's position, starting at 0 (the first item is 0, as in $list[0]$) |
--type:condition
| Parameter | Value | Default | Description |
|---|---|---|---|
--condition required | condition | ||
--check | one of before, after | before | before: the condition is tested before every round (the body may never run); after: the body runs once first and the condition is tested after every round (do-while) |
--type:excelrows
| Parameter | Value | Default | Description |
|---|---|---|---|
--session required | text | Session name given when the workbook was opened Names a excel session opened earlier. | |
--sheet | text | Defaults to the active sheet | |
--header | true / false | true | First row holds column names |
--variable required | variable name | ||
--index | variable name | Variable that receives the round's position, starting at 0 (the first item is 0, as in $list[0]$) |
--type:eachfile
| Parameter | Value | Default | Description |
|---|---|---|---|
--folder required | text | A folder on the agent machine. | |
--filter | text | *.* | |
--subfolder | true / false | false | Include subfolders |
--variable required | variable name | ||
--index | variable name | Variable that receives the round's position, starting at 0 (the first item is 0, as in $list[0]$) |
--type:eachfolder
| Parameter | Value | Default | Description |
|---|---|---|---|
--folder required | text | A folder on the agent machine. | |
--subfolder | true / false | false | Include subfolders |
--variable required | variable name | ||
--index | variable name | Variable that receives the round's position, starting at 0 (the first item is 0, as in $list[0]$) |
--type:queue
Takes work items from a queue until it is empty, one per round: an item whose round ends normally is completed, one whose round fails is failed (and retried later while the queue allows) while the loop goes on with the next item.
| Parameter | Value | Default | Description |
|---|---|---|---|
--queue required | text | Name of the work queue (Queues page) | |
--variable required | variable name | The work item: $item.Data.Field$, $item.Reference$, $item.Id$, $item.Attempt$ | |
--index | variable name | Variable that receives the round's position, starting at 0 (the first item is 0, as in $list[0]$) |
--type:mail
Runs once per e-mail of a mailbox folder that matches the filters, newest first. The messages are read when the loop starts (as mail --action:read); inside, mail --action:saveattachments, move, markread or delete --id:$msg.Id$ work on the current one.
| Parameter | Value | Default | Description |
|---|---|---|---|
--server required | text | IMAP server, e.g. imap.gmail.com or outlook.office365.com | |
--port | number | 993 | 993 for TLS (usual), 143 for STARTTLS or unencrypted |
--vault | text | Vault that holds the mail account (Vaults page); --credential is then the name of the credential in it | |
--credential required | any value | The mail account: the name of a credential in --vault (its user name and password, kept on the Vaults page), or a credential variable ($cred$). Gmail, Outlook.com and Yahoo need an app password; with --authtype:oauth2 the credential is the app registration (client id / client secret) | |
--security | one of auto, ssl, starttls, none | auto | auto: TLS on ports 465/993, STARTTLS when the server offers it on other ports (a password is never sent unencrypted); ssl: TLS from the start; starttls: must switch to TLS; none: unencrypted (internal servers only) |
--ssl | true / false | Older form of --security: false = none, true = TLS or STARTTLS (--security wins when both are set) | |
--timeout | number | 60 | Seconds to wait for the mail server before giving up |
--ignoresslerrors | true / false | false | Accept any server certificate (internal servers with a self-signed certificate); keep false for public servers |
--authtype | one of password, oauth2 | password | oauth2: Microsoft 365 sign-in with an app registration (IMAP.AccessAsApp / SMTP.SendAsApp), for mailboxes where password sign-in is switched off |
--tenant | text | oauth2: the Microsoft 365 directory, e.g. contoso.onmicrosoft.com or its id | |
--mailbox | text | oauth2: the address whose mailbox is used (send: the --from address when empty) | |
--folder | text | INBOX | Mail folder, e.g. INBOX or Processed (mail --action:folders lists them) |
--unread | true / false | true | Only unread messages |
--from | text | Only messages whose sender contains this | |
--to | text | Only messages whose recipients contain this | |
--subject | text | Only messages whose subject contains this | |
--body | text | Only messages whose text contains this | |
--since | any value | Only messages received on or after this date | |
--before | any value | Only messages received before this date | |
--hasattachments | true / false | true: only messages with attachments; false: only messages without | |
--max | number | 50 | At most this many messages |
--markread | true / false | false | Mark all the messages read when the loop starts (before the rounds run) |
--variable required | variable name | The current message: $msg.Subject$, $msg.From$, $msg.FromName$, $msg.To$, $msg.Cc$, $msg.Date$, $msg.Body$, $msg.HtmlBody$, $msg.IsRead$, $msg.Attachments$, $msg.Id$ | |
--index | variable name | Variable that receives the round's position, starting at 0 (the first item is 0, as in $list[0]$) |
Examples
loop --type:range --from:1 --to:10 --step:1 --variable:i
log --message:"Index: $i$"
endloop
loop --type:list --list:$myList$ --variable:item
log --message:"Item: $item$"
endloop
loop --type:condition --condition:$counter$<100
number --action:increment --name:counter --by:1
endloop
break Break
Exits the current loop.
continue Continue
Skips to the next loop iteration.