Workflow Design: Branches, Loops and Fast Lanes
Design workflows that branch and loop: run seven sample orders through tests, find the rush order that skipped an approval check and add a safe default path.
In this lesson you will
- Design branches with a clear order
- Use a loop to process each line of an order
- Spot a branch that hides a risk
- Add a default path for unexpected cases
About 25 minutes
One order, three different paths
Ravi’s print shop gets orders by form. Most are small and need nothing more than a confirmation. A few are big enough that Ravi wants to look before he commits the press. Some are rush orders that must jump the queue, and now and then a form arrives with nothing in it at all. A single straight line of steps cannot cope with all of that. The workflow needs to branch, taking different paths for different orders, and to loop, repeating a step for every line of an order. These two ideas, branches and loops, are how simple automations grow into useful ones.
Branches: if this, then that path
A branch is a decision point. The workflow tests a condition and follows one path or another. Most platforms call this a router, a filter or a paths step, and the names differ, but the idea is identical to the conditions you met in the beginner lessons. Two details decide whether a branching workflow behaves well. The first is order: if several branches could match, usually the first one wins, so the order of your tests is part of the design. The second is a default path for anything that matches no branch, because something always does.
Loops: do it for every line
An order can have several lines, such as flyers and cards on one form. A loop, often called iterate or for each, runs the same steps once per line. You use it to add up a total, to create one row per line in a sheet or to check each line against a rule. Remember that a loop multiplies work: an order with fifty lines runs your steps fifty times, which matters if each step costs time or money, as lesson 8 explained.
Watch it run
The program below holds seven made-up orders in sample money. The inner loop adds up the lines of each order. Then a chain of tests picks a branch: an order with no lines is an error, a rush order goes to the fast lane, an order above the limit of 60 needs Ravi’s approval, and everything else is confirmed automatically. A rush order is tested before the size, so it never reaches the approval test.
# MADE-UP orders in sample money: lines are (item, quantity, unit price)
orders = [
("A1", "Sam", [("flyers", 200, 0.12), ("cards", 100, 0.30)], False),
("A2", "Ana", [("banner", 2, 35.00)], False),
("A3", "Kim", [("posters", 50, 0.80)], True),
("A4", "Lee", [("flyers", 1000, 0.09), ("stickers", 300, 0.15)], True),
("A5", "Raj", [("cards", 250, 0.26)], False),
("A6", "Zoe", [("mugs", 4, 8.50)], False),
("A7", "Max", [], False),
]
limit = 60 # orders above this total need approval
branches, lines_seen, both = {}, 0, []
for oid, who, lines, rush in orders:
total = 0
for item, qty, price in lines: # the loop: one pass per line
total += qty * price
lines_seen += 1
total = round(total, 2)
if not lines:
branch = "error: no lines"
elif rush:
branch = "fast lane"
if total > limit:
both.append(oid)
elif total > limit:
branch = "needs approval"
else:
branch = "auto confirm"
branches[branch] = branches.get(branch, 0) + 1
print(f"{oid}: {total:.2f} -> {branch}")
print("lines processed:", lines_seen)
for name, n in sorted(branches.items()):
print(f"{name}: {n}")
print("rush and over the limit:", both)
A1: 54.00 -> auto confirm
A2: 70.00 -> needs approval
A3: 40.00 -> fast lane
A4: 135.00 -> fast lane
A5: 65.00 -> needs approval
A6: 34.00 -> auto confirm
A7: 0.00 -> error: no lines
lines processed: 8
auto confirm: 2
error: no lines: 1
fast lane: 2
needs approval: 2
rush and over the limit: ['A4']
The loop handled 8 lines in all. Order A1 came to 54.00 and was confirmed automatically, while A2 at 70.00 and A5 at 65.00 were over the limit and went to approval, 2 orders in total. The fast lane took 2 orders, A3 and A4. The one empty order, A7, went down the error path, so 1 order was caught by the safety net, and 2 orders were confirmed automatically. Now look at the last line. It lists A4, a rush order whose total of 135.00 is well over the limit. Because the rush test came first, that large order skipped the approval check completely. Whether that is acceptable is a business decision, but the workflow should never make it by accident. This is the classic branching bug: an earlier branch quietly swallows cases that a later branch was meant to see.
Designing branches that hold up
- List every branch and its condition on paper before you build.
- Ask of each pair of branches: can one order match both? If yes, decide which should win and why.
- Always add a default path that sends the unexpected to a person.
- Put the most careful checks first, because the first match wins.
- Test one example per branch, plus one that matches two and one that matches none.
A useful habit is to write the branch conditions as a small table of examples, with the expected path for each, before building. When the platform’s test mode shows a different path from the one you expected, you have found a design problem early, while it is cheap to fix.
Assuming that branches are independent. Order matters, and an early branch can hide a risk that a later branch was designed to catch.
The orders, prices and limit are made up, in sample money. Platforms name branches and loops differently and may limit how many you can use on your plan, so check your own tool’s documentation.
Practice for this lesson
Check what you learned
Five quick questions. Pick an answer and you will see straight away whether it is right and why.
What is a branch in a workflow?
- A copy of the workflow
- A decision point that sends items down different paths
- A kind of error
- A password
The workflow tests a condition and follows a path.
What does a loop do?
- Stops the workflow
- Sends a reminder
- Deletes data
- Repeats steps once for each item, such as each order line
The sample loop added up every line of each order.
Why did order A4 skip the approval check?
- The rush test came first and the first match wins
- It was too small
- It had no lines
- The limit was zero
A rush order never reached the size test.
What should a default path do?
- Delete the item
- Confirm it automatically
- Send anything unexpected to a person
- Repeat the loop
Unmatched cases need a safe home.
How do loops affect cost?
- They make every step free
- They stop retries
- They only run once a day
- An order with many lines runs your steps many times
Each pass through a loop repeats the work.
Summary
- Branches send items down different paths, and the first match usually wins.
- Loops repeat steps for every line or item.
- Check that an early branch does not skip a later safety check.
- Always provide a default path to a person.
Questions
Do all platforms have branches and loops?
Most offer something like them, under different names and sometimes limited by plan. Check your tool's documentation.
How many branches are too many?
When you can no longer describe each branch in one sentence, consider splitting the workflow into smaller ones.
Are those order totals real?
No. They are made-up sample figures in sample money.
