---
title: Conditional logic
source: https://docs.newrelic.com/docs/workflow-automation/workflow-examples/basic-patterns/conditional-logic
---

Use switch statements to make decisions based on data from previous steps.

**What switch statements enable:**

-   Create decision trees based on conditions
-   Route workflow execution to different steps based on data values
-   Evaluate multiple conditions in sequence
-   Define default behavior when no conditions match

## Conditional logic with data

```yaml
  steps:
    - name: checkCPU
      type: action
      action: newrelic.nerdgraph.execute
      version: 1
      # ... query configuration

    - name: decideAction
      type: switch
      switch:
        - condition: "${{ .steps.checkCPU.outputs.data.actor.account.nrql.results[0].average > 90 }}"
          next: resizeInstance
        - condition: "${{ .steps.checkCPU.outputs.data.actor.account.nrql.results[0].average > 70 }}"
          next: sendWarning
      next: normalOperation

    - name: resizeInstance
      type: action
      action: aws.ec2.modifyInstanceAttribute
      version: 1
      # ... resize configuration

    - name: sendWarning
      type: action
      action: slack.chat.postMessage
      version: 1
      # ... warning message

    - name: normalOperation
      type: action
      action: newrelic.ingest.sendLogs
      version: 1
      # ... log normal status
```

## Related topics [#related-topics]

[Loops](https://docs.newrelic.com/docs/workflow-automation/workflow-examples/basic-patterns/loops)

Combine conditional logic with iteration

[Slack integration](https://docs.newrelic.com/docs/workflow-automation/workflow-examples/integrations/slack)

Apply switch patterns to approval workflows

[Definition schema: Switch](https://docs.newrelic.com/docs/workflow-automation/workflow-automation-apis/definition-schema#switch)

Complete switch step reference
