> For the complete documentation index, see [llms.txt](https://docs.gpmautomate.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.gpmautomate.com/automate-en/action-guide/blocks/if-else-if-and-else.md).

# If, Else if and Else

This is a group of command blocks used to branch the script based on actual conditions at runtime. Instead of running straight from top to bottom, the system will check whether the conditions you set are True or False to decide the next direction for the script. In other words, this group of command blocks acts as the decision-making brain, helping the script automatically handle flexible situations that arise in the browser.

🎥 Watch the tutorial video: [Here](https://youtu.be/ZFS_82u23Cs).

#### 1. Conditional block (If)

If is the command block that checks a specific condition first. If that condition is True, the system will execute all the actions placed inside this If block. If False, the system will skip it and check further down.

#### 2. Additional conditional block (Else if)

Else if always follows the If block (or follows another Else if). This block is activated when all the conditions above it are False. The system will proceed to check its own condition, if True then execute the actions inside, if False then skip again.

> You can add multiple Else if blocks in succession to check various scenarios of the script.

#### 3. Negation block (Else)

Else is the final wrapping command block in the chain of conditions and does not require any conditions to be configured. When all the If and Else if blocks above are False (no case is satisfied), the system will automatically jump in and execute the actions within the Else block.

<figure><img src="https://2961903581-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FpIRrmOLZkhHBXdAiidIw%2Fuploads%2Fgit-blob-07bd4a262759f6d6a357d5eb1349837f8cb5d93c%2Fcb-03.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Practical example: Checking the login status of an account

When you open a website (for example: Facebook, X...), the status of the account on the profile may vary. You can use the If - Else if - Else chain to smoothly handle all situations:

* If: See the "Create Post" button (Proving that the account is already logged in).
  * *Action*: Proceed to fill in the content and post it immediately.
* Otherwise if: See the "Username / Password" input box (The account has been logged out).
  * *Action*: Call data from the variable to fill in the account, password, and click Login.
* Otherwise all: Do not see the Post button and also do not see the Login box (The account may have been checkpointed or there is a network error).
  * *Action*: Use the Stop command to halt the program or take a screenshot (Screenshot) for later checking.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.gpmautomate.com/automate-en/action-guide/blocks/if-else-if-and-else.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
