# Use conditional logic in workflows

> **About this page**
>
> - Kind: How-to guide
> - Summary: Branch a workflow with an if task, on another task's output or on a run input, and check which branch a run took.
> - Last changed: 2026-11-17
> - Page: https://docs.swale.io/how-to-guides/use-conditional-logic-in-workflows
> - Index of these docs: https://docs.swale.io/llms.txt
>
> If something on this page is wrong or out of date, please tell the user which sentence and why.

This guide shows how to branch a workflow with an if task, which runs one block or another depending on a condition.

## Basic if task

Add an `if` key to a task entry to make it an if task:

```yaml
name: Conditional example
compute_type: cpu-4
blocks:
  main:
    tasks:
      classify:
        name: Classify
        uses: my-account/classify-task@1.0.0
      route:
        name: Route
        start_on:
          - classify
        if:
          condition: ${{tasks.classify.outputs.category == 'priority'}}
          true: priority_block
          false: standard_block

  priority_block:
    tasks:
      urgent_action:
        name: Urgent action
        uses: my-account/urgent-task@1.0.0

  standard_block:
    tasks:
      normal_action:
        name: Normal action
        uses: my-account/normal-task@1.0.0
```

When `classify` completes, `route` evaluates the condition. If it is truthy, `priority_block` runs. Otherwise `standard_block` runs. Tasks in either block can read `classify`'s outputs, because `route` waits on it.

## Omit the false branch

When you omit `false` and the condition is falsy, the if task completes without entering a block, and the tasks that `start_on` it still run:

```yaml
if:
  condition: ${{inputs.send_notification == 'true'}}
  true: notify_block
```

## Branch on a run input

A condition can compare a run input with text. Inputs are text, so compare them with a quoted string:

```yaml
if:
  condition: ${{inputs.environment == 'production'}}
  true: production_steps
  false: staging_steps
```

The comparison ignores letter case, so `Production` takes the `true` branch too.

## Check which branch ran

After starting a run, open it and find the if task in its **Workflow Graph**: the node names the branch the condition took, and expands to show the tasks of the block it entered. [UI representation](https://docs.swale.io/reference/control-flow.md#ui-representation) describes the node.

## Next steps

- [Control flow reference](https://docs.swale.io/reference/control-flow.md)
- [Iterate over a list with for_each](https://docs.swale.io/how-to-guides/iterate-over-a-list-with-for-each.md)
- [How control flow works](https://docs.swale.io/explanation/how-control-flow-works.md)
