> For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

# return

> Return from the current section, optionally with a value.

Return from the current section. Inside a subroutine called via
[`execute`](/docs/swml/reference/messaging/execute), control returns to the caller and the value is
accessible as `return_value` in the caller's context. In `main`, `return` stops execution entirely
(its value is discarded).

To return without a value, use `return: null`.

## **Properties**

The value to return. Accepts any type. Use `null` to return no value.

## **Variables**

When called from a section invoked via [`execute`](/docs/swml/reference/messaging/execute),
`return` provides the variable below to the caller's context once execution resumes. When
called from `main`, `return` stops execution immediately and no variable is set anywhere.

The value supplied to `return`. Available in the caller's context after the `execute` step
that invoked this section completes. String values are expanded for `%{...}` placeholders
before storage; objects and arrays are stored as-is.

## **Examples**

### Return a string from a subroutine

```yaml
version: 1.0.0
sections:
  main:
    - execute:
        dest: greet
    - reply:
        body: "%{return_value}"
  greet:
    - return: "Hello there!"
```

```json
{
  "version": "1.0.0",
  "sections": {
    "main": [
      {
        "execute": {
          "dest": "greet"
        }
      },
      {
        "reply": {
          "body": "%{return_value}"
        }
      }
    ],
    "greet": [
      {
        "return": "Hello there!"
      }
    ]
  }
}
```

### Return with no value (exit a section without setting `return_value`)

```yaml
version: 1.0.0
sections:
  main:
    - execute:
        dest: maybe_reply
    - reply:
        body: "Done."
  maybe_reply:
    - switch:
        variable: message.body
        transform: lowercase_trim
        case:
          stop:
            - reply:
                body: "You've been unsubscribed."
            - return: null
        default:
          - return: null
```

```json
{
  "version": "1.0.0",
  "sections": {
    "main": [
      {
        "execute": {
          "dest": "maybe_reply"
        }
      },
      {
        "reply": {
          "body": "Done."
        }
      }
    ],
    "maybe_reply": [
      {
        "switch": {
          "variable": "message.body",
          "transform": "lowercase_trim",
          "case": {
            "stop": [
              {
                "reply": {
                  "body": "You've been unsubscribed."
                }
              },
              {
                "return": null
              }
            ]
          },
          "default": [
            {
              "return": null
            }
          ]
        }
      }
    ]
  }
}
```

### Return from `main` to stop execution

```yaml
version: 1.0.0
sections:
  main:
    - reply:
        body: "Got it."
    - return: null
```

```json
{
  "version": "1.0.0",
  "sections": {
    "main": [
      {
        "reply": {
          "body": "Got it."
        }
      },
      {
        "return": null
      }
    ]
  }
}
```