---
title: "Action if_else"
description: "Conditional scenario branching by expressions with AND/OR support and constant assignment."
---

# Action `if_else`

> **System ID:** `action_if_else`

## Description

Evaluates conditions and routes the scenario to the matching branch. Supports simple comparisons, AND/OR logic, placeholders, and setting constants in the block that matched. Order: `if` → `elseif` → `else`.

## Events (scenario branches)

| Event | When it occurs |
|-------|----------------|
| **(name from config)** | A condition in an `if` / `elseif` / `else` block matched; the name comes from the `event` field or the condition mapping |
| **default** | No condition matched and `else` has no `event` |

## Parameters

| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| `if` | object | no | `{}` | Main condition block |
| `elseif` | object | no | `{}` | Additional blocks (can be several) |
| `else` | object | no | `{}` | Default block if all conditions are false |

Condition formats in a block:

- simple: `"{{param}}>3": "event_name"`
- AND: `"and": ["{{a}}>=1", "{{b}}<=2"], "event": "e2"`
- OR: `"or": ["{{a}}==1", "{{b}}==2"], "event": "e3"`
- constants: `"set": {"key": "value"}`
- compare strings in single quotes: `"'{{name}}'=='John'"`

## Configuration example

```json
{
  "if": {
    "{{total}}>3": "gt3",
    "set": {
      "doubled": "(({{total}}*2))"
    }
  },
  "elseif": {
    "{{status}}!=1": "ne1"
  },
  "else": {
    "event": "fallback",
    "set": {
      "flag": "fallback"
    }
  }
}
```

## Related docs

- [Actions reference](/en/actionjail/reference/actions-reference.md)
