2022-02-14 03:22:51 +01:00
|
|
|
---
|
|
|
|
title: if
|
|
|
|
layout: command
|
|
|
|
version: 0.59.0
|
|
|
|
---
|
2021-05-30 02:57:04 +02:00
|
|
|
|
2022-02-14 03:22:51 +01:00
|
|
|
Conditionally run a block.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
|
|
|
```> if (cond) (then_block) (else_expression)```
|
2021-05-30 02:57:04 +02:00
|
|
|
|
|
|
|
## Parameters
|
|
|
|
|
2022-02-14 03:22:51 +01:00
|
|
|
- `cond`: condition to check
|
|
|
|
- `then_block`: block to run if check succeeds
|
|
|
|
- `else_expression`: expression or block to run if check fails
|
2021-05-30 02:57:04 +02:00
|
|
|
|
|
|
|
## Examples
|
2022-02-14 03:22:51 +01:00
|
|
|
|
|
|
|
Output a value if a condition matches, otherwise return nothing
|
|
|
|
```shell
|
|
|
|
> if 2 < 3 { 'yes!' }
|
|
|
|
```
|
|
|
|
|
|
|
|
Output a value if a condition matches, else return another value
|
2021-05-30 02:57:04 +02:00
|
|
|
```shell
|
2022-02-14 03:22:51 +01:00
|
|
|
> if 5 < 3 { 'yes!' } else { 'no!' }
|
|
|
|
```
|
2021-05-30 02:57:04 +02:00
|
|
|
|
2022-02-14 03:22:51 +01:00
|
|
|
Chain multiple if's together
|
2021-05-30 02:57:04 +02:00
|
|
|
```shell
|
2022-02-14 03:22:51 +01:00
|
|
|
> if 5 < 3 { 'yes!' } else if 4 < 5 { 'no!' } else { 'okay!' }
|
|
|
|
```
|