> For the complete documentation index, see [llms.txt](https://learn.fi-code.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.fi-code.com/overview/control-structures.md).

# Control Structures

The following control structures can be used in fi:

* if/else
* throw
* assert

We are currently working on a few additional control structures, including:

* foreach
* loop

## If/else

**If** statements allow you to branch your logic in multiple ways based on the resolution of an expression. If the expression resolves as true, the code within the curly braces is executed.

```
if (SENDER == address "tz1NhSA8NV4W3e5ws37u1xzjkgxDCpijyh7m" || OWNER == SENDER) {
    
}
```

### else

A second block of code can be placed within curly braces after the initial block, prepended with the else control. You can also use **else if** to define another condition expression to evaluate.

```
if (SENDER == address "tz1NhSA8NV4W3e5ws37u1xzjkgxDCpijyh7m") {
    return.isOwner = bool True;
} else if (nat 2 == add(nat 1, to_nat(sub(nat 5, int 2, nat 2)))){

} else {

}
```

## Throw

This allows the developer to exit execution of the script - an optional value can be provided as an argument, which will be returned as an error.

```
if (SENDER != SOURCE){
    throw(string "Error with sender");
}
```

## Assert

The assert allows the developer to exit execution if a condition returns false - essentially the combination of an if and a throw. The first argument must be the condition to evaluate, and the optional second argument can be the value to be returned as an error. The previous example can also be written as:

```
assert(SENDER == SOURCE, string "Error with sender");
```


---

# 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 dynamically by asking a question.

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

```
GET https://learn.fi-code.com/overview/control-structures.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.
