nushell/docs/commands/if.md
Justin Ma c0a1d18e3d
update #4455, regenerate commands' docs and update make_docs script (#4586)
* feat: update #4455, regenerate commands' docs

* chore: update make_docs script
2022-02-21 11:26:00 -06:00

35 lines
638 B
Markdown

---
title: if
layout: command
version: 0.59.0
---
Conditionally run a block.
## Signature
```> if (cond) (then_block) (else_expression)```
## Parameters
- `cond`: condition to check
- `then_block`: block to run if check succeeds
- `else_expression`: expression or block to run if check fails
## Examples
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
```shell
> if 5 < 3 { 'yes!' } else { 'no!' }
```
Chain multiple if's together
```shell
> if 5 < 3 { 'yes!' } else if 4 < 5 { 'no!' } else { 'okay!' }
```