# Boolean logic in Rewst workflows

## Boolean values and their role in automation

*Boolean* values represent simple yes/no conditions, like on/off or true/false. They define rules and logic in workflows by evaluating conditions.

Boolean values are fundamental in automation workflows, controlling decision-making and process flow. Understanding Boolean logic helps ensure that workflows are efficient, reliable, and easy to maintain.

## Key boolean concepts

* **Boolean values**: Represent `true` or `false`, similar to `1` (on) and `0` (off).
* **Logical operators**: `and`, `or`, `not` determine conditions in workflows.
* **Comparison operations**: Evaluate conditions (e.g., `user_role == "admin"`).
* **Custom conditions in workflows**: Enable transitions based on Boolean evaluations.

## Boolean operators in Rewst workflows

Boolean logic controls workflow decisions using these key operators:

* **`and`** – Requires both conditions to be true.
  * Example: `user_logged_in and is_admin`
* **`or`** – Requires at least one condition to be true.
  * Example: `is_manager or is_admin`
* **`not`** – Inverts a Boolean value.
  * Example: `not user_logged_in` (returns `true` if `user_logged_in` is `false`).

## Boolean logic in action

* **True and false = false** – Both conditions must be true for `and` to return `true`.
* **True or false = true** – Only one condition needs to be true for `or` to return `true`.
* **Not false = true** – Flips the Boolean value to its opposite.

## Best practices for boolean logic in Rewst

To ensure efficiency and maintainability, follow these best practices.

### Structuring logical conditions

* **Group logic with parentheses**: Ensures conditions execute in the correct order.
  * Example: `(is_admin and is_active) or is_super_admin`
* **Use `in` for cleaner conditions**:
  * Before: `if role == "admin" or role == "super_admin"`
  * After: `if role in ["admin", "super_admin"]`

### Simplifying boolean expressions

* **Use ternary operators for concise logic**:
  * Syntax: `variable = value_if_true if condition else value_if_false`
  * Example: `status = "Active" if is_active else "Inactive"`
* **Leverage short-circuit evaluation**:
  * Skips unnecessary checks by placing the most likely condition first.
  * Example: `if user_logged_in and is_admin:` (Skips `is_admin` check if `user_logged_in` is `false`.)

{% hint style="info" %}
For more on how boolean values relate to Rewst, complete our Clean Automation course in Cluck University.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.rewst.help/documentation/automations/workflows/boolean-logic-in-rewst-workflows.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
