RPA Control Flow Basics
Control flow determines the order in which a bot executes its steps. Without control flow, a bot runs every activity in a straight line from top to bottom, with no decisions and no repetition. Control flow adds the ability to make decisions (IF conditions), repeat steps (loops), and stop early (break). It transforms a simple list of steps into a smart, flexible automation.
The Three Pillars of Control Flow
┌────────────────────────────────────────────────┐ │ CONTROL FLOW │ │ │ │ ┌──────────────┐ ┌──────────┐ ┌──────────┐ │ │ │ DECISIONS │ │ LOOPS │ │ SEQUENCE│ │ │ │ (IF/Switch) │ │ (Repeat) │ │ (Order) │ │ │ └──────────────┘ └──────────┘ └──────────┘ │ └────────────────────────────────────────────────┘
Decisions – IF / ELSE
An IF condition checks whether something is True or False and runs different steps depending on the result. This is how bots make choices without human involvement.
Basic IF Structure
IF [invoiceAmount > 5000]
├── THEN (True path):
│ Send approval email to manager
│ Mark item as "Pending Approval"
└── ELSE (False path):
Post invoice directly in SAP
Mark item as "Posted"
Nested IF Example
IF [vendor is on approved list]
├── THEN:
│ IF [invoice amount > 5000]
│ ├── THEN: Send for director approval
│ └── ELSE: Post directly
└── ELSE:
Send exception email to procurement
Skip invoice
Switch Statement (Multiple Conditions)
A Switch checks one variable against multiple possible values. Use it instead of many nested IF-ELSE statements when one variable determines which path to take.
Switch [invoiceStatus] ├── Case "NEW": Process the invoice ├── Case "PENDING": Check approval and wait ├── Case "APPROVED": Post to SAP ├── Case "REJECTED": Send rejection notice └── Default: Log unknown status error
Loops – Repeating Steps
Loops make a bot repeat the same steps for every item in a collection — every row in a spreadsheet, every email in an inbox, every file in a folder.
For Each Row In DataTable
This is the most common loop in RPA. It processes one row at a time from a DataTable (like a spreadsheet loaded into memory).
Load Excel data into DataTable: invoiceTable (200 rows of invoices) FOR EACH row IN invoiceTable: ├── Read: vendorName = row["Vendor"].ToString() ├── Read: amount = CDbl(row["Amount"]) ├── Read: invoiceNo = row["Invoice No"].ToString() ├── Call: PostToSAP(vendorName, amount, invoiceNo) └── Log result Loop repeats 200 times. Bot processes all 200 invoices automatically.
While Loop
A While loop keeps repeating as long as a condition is True. Use it when you do not know how many times you need to repeat — for example, keep checking a web page until a status changes.
WHILE [orderStatus = "Processing"] ├── Wait 30 seconds ├── Refresh order page ├── Read [Order Status Label] → orderStatus └── (Loop back and check again) Exit loop when orderStatus = "Completed" or "Failed"
For Loop (Counter Loop)
A For loop runs a fixed number of times. Use it when you know exactly how many repetitions you need — for example, retry a failed action exactly 3 times.
FOR i = 1 TO 3 ├── Try to log in to SAP ├── IF login successful: EXIT loop └── ELSE: Wait 60 seconds, try again IF still failed after 3 tries: Send alert to IT
Sequence vs Flowchart
In UiPath, you choose how to organise your workflow:
Sequence
Activities run strictly top-to-bottom. Best for simple, linear processes with few branches. Easy to read and understand at a glance.
[Open Browser]
│
▼
[Navigate to URL]
│
▼
[Type Username]
│
▼
[Type Password]
│
▼
[Click Login]
Flowchart
Activities connect with arrows and can branch in multiple directions. Best for complex logic with many decisions and loops. Gives a visual map of the entire process.
[Start]
│
▼
[Get Item from Queue]
│
Item found?
/ \
YES NO ──▶ [Send Summary] ──▶ [End]
│
▼
[Process Invoice]
│
Success?
/ \
YES NO
│ │
[Log OK] [Log Error]
│ │
└─────┬─────┘
│
[Get Next Item] ◀── Loop back
Break and Continue
Inside loops, you sometimes need to exit early or skip an item:
- Break: Exits the loop entirely and continues with whatever comes after the loop.
- Continue: Skips the rest of the current loop iteration and jumps to the next item.
FOR EACH row IN invoiceTable ├── IF row is empty: CONTINUE → skip this row, go to next ├── IF critical error: BREAK → stop processing, exit loop └── ELSE: Process normally
Retry Scope
Retry Scope is a special UiPath control flow container that automatically retries a set of activities if they throw an error. You set the number of retries and the interval between them.
RETRY SCOPE
├── Retries: 3
├── Retry Interval: 00:00:30 (30 seconds)
└── Activities to retry:
[Navigate to URL]
[Wait for Page Load]
[Click Login Button]
If all three retries fail → exception is thrown → error handling kicks in
Summary
Control flow is what makes a bot intelligent and efficient. IF conditions allow bots to make decisions. Loops allow bots to process large volumes of data without repeating code. Sequences organise simple linear tasks. Flowcharts map complex multi-branch processes. Break and Continue give you precise control inside loops. Retry Scope handles transient failures gracefully. Mastering control flow is what separates a functional bot from a robust, production-grade automation.
