# Using Variables

Variables are for saving or updating data that you temporarily need during your TaskBot run.

Since *Variables* don't adhere to any appending or looping logic, it's a powerful, robust and flexible way to save or update any data that you **temporarily** need in order to advance in your workflow without having to worry about loop set-up.&#x20;

### When to Use Tables and When to Use Variables

#### Example: Use variable to limit number of DMs sent per run

To understand the differences between tables and variables, let's go over an example.

Imagine you want to send an automated DM to a list of profiles. However, you want to limit the number of profiles that you reach out to per day or per run. Let's say, you want your TaskBot to never send more than 30 DMs per run.

**Step 1: Initial table set-up**

Let's assume your list of profiles is stored in the table called "Profile links", as shown below. (See [How to Add Tables](/using-zerowork/using-tables/how-to-add-tables.md)).

<figure><img src="/files/jTAvGtrDpTE8uA1Jgi2C" alt=""><figcaption></figcaption></figure>

**Step 2: Initial TaskBot set-up**

To start sending DMs, you would build a TaskBot that first opens the website where DMs can be sent, then loops through the rows in your table, inserts text into DM input and clicks on "Send" button.

The TaskBot set-up would look like this:

<figure><img src="/files/tFl2l7VgNnv5apCqLRR2" alt=""><figcaption></figcaption></figure>

Here is the set-up of the *Start Repeat* building block (see [Start Repeat](/using-zerowork/using-building-blocks/start-repeat.md)).

<figure><img src="/files/18QckItUVKbsB0WsNTFU" alt=""><figcaption></figcaption></figure>

**Step 3: Creating a variable**

Now, let's add the limit.

To ensure that TaskBot doesn't send more than 30 DMs, we need a counter which should increment by 1 each time TaskBot sends a DM. This is a great example where you need a variable. A table would not be an appropriate choice for this use case because we don't need 30 rows with a counter number (as in 1, 2, 3, 4, 5, etc.), instead we need a **single** value that **dynamically** increments during the TaskBot run.

First, we need to create a variable, as shown below.

<figure><img src="/files/NSigaOahHK4Xgh497Acv" alt=""><figcaption></figcaption></figure>

Let's call the new variable "DM counter". You can leave the variable value empty or you can enter "0" (as the count should start with 0).

<figure><img src="/files/x6RSwwqEN7hgMej5thgl" alt=""><figcaption></figcaption></figure>

**Step 4: Updating the counter during TaskBot run**

Let's now add the logic to update the variable during the TaskBot run. To update "DM counter", use the building block [Number Operations](/using-zerowork/using-building-blocks/number-operations.md).

<figure><img src="/files/8aRNHxqTAlCJMDFLB3jM" alt=""><figcaption></figcaption></figure>

This is the set-up of the *Number Operations* building block that adds 1 in every loop iteration (and every loop iteration sends a DM):

<figure><img src="/files/F25fzKXVWyes5Gpc5fPO" alt=""><figcaption></figcaption></figure>

**Step 5: Setting up a condition to check the counter**

The last piece that is missing is a condition that checks if the counter is less than 30. This is how to add that:

<figure><img src="/files/YH5okTi2QN3akzSu7Aon" alt=""><figcaption></figcaption></figure>

Conditions are set using *Start Condition* and *Set Condition* building blocks (see [Start Condition and Set Condition](/using-zerowork/using-building-blocks/start-condition-and-set-condition.md)). Here is the set-up of the *Set Condition*:

<figure><img src="/files/XDX8LyFIQD6Yn0iTClFY" alt=""><figcaption></figcaption></figure>

### Video Tutorial

{% embed url="<https://youtu.be/cZr_8nDA0os?si=R_s52LungQdaPSaF>" %}


---

# 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.zerowork.io/using-zerowork/using-variables.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.
