> ## Documentation Index
> Fetch the complete documentation index at: https://dokumentation.websale.de/llms.txt
> Use this file to discover all available pages before exploring further.

# Control structures

> Reference for WEBSALE control structures: boolean values, if and switch branches and foreach loops used to drive conditional template output.

## Boolean/Bool (true/false)

A bool is a truth value and can only be *true* or *false*.

|          |                                          |
| -------- | ---------------------------------------- |
| `true`   | truth value true                         |
| `false`  | truth value false                        |
| `"true"` | not a truth value (wrong syntax: string) |

Boolean values are mostly produced in combination with comparison operators. For example, when comparing one value with another, the result is either true or false.

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
{{ if $quantity == 1 }}
    Displayed when the value of the variable $quantity equals 1.
{{ /if }}
```

## truthy and falsy

Not only values of the data type bool contain a truth value. Objects of all other data types also have a value property referred to as *truthy* or *falsy*. In the context of logical operators and branching, it is important to know when a value is considered true or false.

Here is a list of all values that are *falsy* and are therefore treated as *false*:

▪ *null*, the value of the Null data type

▪ *false*

▪ the number 0 (*Integer*) or 0.0 (*Float*)

▪ an empty *string " "*

▪ an empty *list \[ ]*

▪ an empty *map*

All other values are treated as *truthy*.

## Converting to boolean

Other base types can be converted to boolean:

```html theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
String: {{= bool(" ")}} // true
String: {{= bool("")}} // false

Integer: {{= bool(1) }} // true
Integer: {{= bool(0) }} // false

Float: {{= bool(1.0) }} // true
Float: {{= bool(0.0) }} // false
```
