# Control Blocks

## Overview

The control blocks are code blocks or segments that control the flow of the app. These blocks are used to manage the order in which different parts of the code execute. They typically include structures like conditionals and loops, which help determine when certain actions or commands should be carried out based on specific conditions.

## Navigate to Screen

The "navigate to screen" block takes the user to the defined screen.&#x20;

<div align="left"><img src="/files/-MZBzgvTlN1eZtwwJ1k6" alt="" width="375"></div>

{% hint style="info" %}
We recommend avoiding placing any additional blocks below the "navigate to screen", "open link" or "send email" blocks because when the app navigates to another screen or exits any subsequent blocks may not have enough time to be executed.&#x20;
{% endhint %}

### Video Tutorial

#### How to Change Thunkable Screens with a Button Click

In this tutorial, you’ll learn how to use the "navigate to screen" block to allow your app’s users to navigate between app screens with a simple button click.

{% embed url="<https://youtu.be/8Nl_eF56ZxY>" %}

## If, Do and If, Do, Else

The "if, do" and "if, do, else" blocks allow you to make decisions in your app. They execute certain actions if a condition is true and different actions if the condition is false.&#x20;

<div align="left"><figure><img src="/files/tczYXsSqF4SJLkOYp5Ii" alt=""><figcaption></figcaption></figure></div>

To transform the "if, do" block to support more complex logic:

1. Click the plus icon next to the "if" statement, this will add an additional "else if" statement.&#x20;

   <div align="left"><figure><img src="/files/MLPvtI4QEpfqdpzCtEtd" alt=""><figcaption></figcaption></figure></div>
2. Click the plus icon next to the "do" statement, this will add an additional "else" statement.&#x20;

   <div align="left"><figure><img src="/files/ghwBRF2alHH3CVj5HJU8" alt=""><figcaption></figcaption></figure></div>
3. To remove an "else" or "else if" statement, click on the minus sign next to statement you wish to remove.&#x20;

   <div align="left"><figure><img src="/files/C7PNDfjEkYSjw50Z3wu4" alt=""><figcaption></figcaption></figure></div>

A truthy value is a value that is considered true when encountered in a Boolean context. All values are true unless they are defined as false. That is, all values are truthy except false, 0, "", null, undefined, and NaN.

**Returns False:**

<div><figure><img src="/files/RmUFLtkZiFU05KM5QBOt" alt=""><figcaption></figcaption></figure> <figure><img src="/files/R8JUtsTq04F97JWUCRDu" alt=""><figcaption></figcaption></figure></div>

<div><figure><img src="/files/G4vmf2fr2jkn7c0e6gMG" alt=""><figcaption></figcaption></figure> <figure><img src="/files/2R9fCOQaIjF3FTEUwWRO" alt=""><figcaption></figcaption></figure></div>

**Returns True:**

<div><figure><img src="/files/oOdMOyMQomJa4wdeodLm" alt=""><figcaption></figcaption></figure> <figure><img src="/files/hrUctGFqD9x9sdvWeqPr" alt=""><figcaption></figcaption></figure></div>

<div><figure><img src="/files/BbTvqWmsZtEFWjuvMAYw" alt=""><figcaption></figcaption></figure> <figure><img src="/files/FMxWpXNBuw0uYWWdcuqm" alt=""><figcaption></figcaption></figure></div>

## Wait \[1] Seconds

Wait the specified amount of time before performing the next action.

<div align="left"><img src="/files/KKzXwtjK13GMK7V4DcX2" alt="" width="188"></div>

In general, when blocks are stacked one on top of the other, they are executed simultaneously. To ensure that certain blocks are executed first, you can add a small delay between them. While blocks are asynchronous by nature, they can behave synchronously if you use a "wait" block.&#x20;

## Loops Blocks

Loop control blocks allow you to execute a set of commands multiple times. They are helpful for tasks that need to be repeated, such as iterating through a list of items.

### Forever

Repeat the action for an unlimited period.

<div align="left"><img src="/files/-MXltXm3vgLdk1DKXcMf" alt="" width="188"></div>

### Repeat \[10] Times

Repeat the action the specified number of times.

<div align="left"><img src="/files/FiZ0qDILl3xB2qvx3iMJ" alt="" width="188"></div>

### Count with i from \[1] to \[10] by \[1]

Repeat the action a specified number of times with the incrementer index i.

<div align="left"><img src="/files/J3VH2x9YNJXC3YMQKBo7" alt="" width="375"></div>

### For Each Item j in List

Repeat the action over every item in a list.

<div align="left"><img src="/files/-MXltynkwlo14I0srj1Z" alt="" width="375"></div>

### Repeat While

Repeat the action while a condition is true.

<div align="left"><img src="/files/-MXluIqqMMZEARXVBNC_" alt="" width="375"></div>

### Break out of Loop

Break out of an existing loop.

<div align="left"><img src="/files/G7qKcVWarPgb8SmOYbjX" alt="" width="375"></div>

## Test, If True, If False

This block can return a value based on a given condition. If the condition is true, one value is returned. If the condition is false, a different value is returned.

<div align="left"><img src="/files/-MXlv0afJcaRLvTewo-I" alt=""></div>

## Open Link

The "open link" block opens an installed app or a URL in the device's browser. If the device has the relevant app installed, the link will open in the app. Otherwise, the link will open in the browser.

<div align="left"><img src="/files/-LAn67AX3DtlqidVUA7T" alt=""></div>


---

# 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.thunkable.com/blocks/blocks/control.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.
