Master Conditional Logic in n8n - If-Else Node, Execution Order & Branching

Learn Master Conditional Logic in n8n - If-Else Node, Execution Order & Branching in this comprehensive n8n tutorial. Step-by-step guide with video, code examples, and expert tips from the n8n Zero to Hero course.

Table of Contents

Overview

This lesson is part of the n8n AI Automation - Zero to Hero course, Section: 3. Deep Dive Concepts.

Watch the video above for the full tutorial, or read the written guide below.

What is conditional logic in n8n, and when do you use the IF node versus the Filter node?

The IF node routes every incoming item into one of two branches, a true path or a false path, based on one or more conditions you define. The Filter node evaluates the same kind of conditions but silently discards items that fail and outputs only one branch. Use the IF node when you need to act on both outcomes. Use the Filter node when the false case requires no action and you want a cleaner canvas.

How to build branching workflows, control execution order, and merge results in n8n

n8n supports three branching types. Conditional branching uses the IF node to split a workflow into a true path and a false path, for example flagging a qualified lead versus an unqualified one. Multipath branching uses the Switch node to create any number of output branches, one per matching condition, such as routing orders by status into pending, processing, cancelled, and refunded paths. Parallel branching fires multiple downstream nodes from a single source node at the same time, like sending both an email and a Slack message for every cancelled order from the same branch output.

Execution order in n8n follows two deterministic rules: top-to-bottom first, then left-to-right when nodes sit at the same height on the canvas. One branch runs to completion before the next starts. This sequence matters because if a node in Branch C depends on data produced by Branch A, but Branch C sits higher or further left, n8n executes it first and the workflow breaks or returns empty results. Arranging branches deliberately on the canvas to match the dependency order you need is not optional; it is structural correctness.

The Merge node resolves multi-branch workflows by waiting for all connected branches to finish, then combining their outputs into a single dataset. In the lesson demo, two parallel Google Sheets queries fetch order headers (104 rows) and order details separately. The Merge node joins them on the shared Order ID field and produces 291 unified rows. Every downstream node from that point works on one clean dataset instead of two disconnected streams.

Key Takeaways

  • The IF node creates two executable branches (true and false); the Filter node outputs only matched items with no false branch, making it the right choice when failed conditions need no handling.
  • n8n's three branching types are conditional (IF node, 2 paths), multipath (Switch node, n paths matched by field value), and parallel (multiple nodes connected to one output firing at the same time).
  • Execution order is top-to-bottom then left-to-right, and each branch completes fully before the next starts, so placing a dependent node in the wrong position breaks data availability for that node.
  • The Merge node waits for all incoming branches, combines results on a matching field such as Order ID, and returns one unified dataset so downstream processing stays coherent.
  • Optimizing a multi-branch workflow sometimes means merging branches before a shared action rather than duplicating that action per branch, as shown when cancelled and refunded orders both feed one Merge node before a shared email and Slack step.

Next Steps

Continue your n8n journey with the full n8n AI Automation - Zero to Hero course.

Frequently Asked Questions

The IF node supports AND and OR logic across multiple conditions. In the lesson demo, three AND conditions run together: company name is not empty, email does not end with gmail.com, and email does not end with hotmail.com. All three must be true for an item to reach the true branch. If any one fails, the item routes to the false branch instead.

The Switch node matches an incoming field value against multiple conditions and creates one output branch per match, supporting any number of paths. In the lesson demo it matches order_status against four values and produces four separate branches. The IF node always creates exactly two branches, true and false, regardless of how many conditions you configure inside it.

n8n runs one branch at a time, finishing it completely before starting the next, following a top-to-bottom then left-to-right sequence on the canvas. If a node relies on data from a branch that runs later in that sequence, n8n executes that node before its source data exists, producing empty or incorrect output. Correct branch placement on the canvas is what enforces the right dependency order.

Use the Merge node when two or more branches produce data that must be combined before any further step can work correctly. In the lesson demo, order headers and order details are fetched in parallel and are useless apart because neither contains the full picture. The Merge node joins them on Order ID and produces 291 unified rows, letting the rest of the workflow operate on one complete dataset.

Dheeraj Sharma

Dheeraj Sharma

AI Systems Builder
Creator of the n8n Zero to Hero course (42 lessons, 31+ hours). I help solopreneurs build AI systems that grow revenue without growing workload.

Get the n8n Mastery Bundle

All workflows, cheat sheets, and premium resources from the entire course in one package.

Get Premium Resources