nushell/docs/commands/for.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
605 B
Markdown

---
title: for
layout: command
version: 0.59.0
---
Loop over a range
## Signature
```> for (var_name) (range) (block) --numbered```
## Parameters
- `var_name`: name of the looping variable
- `range`: range of the loop
- `block`: the block to run
- `--numbered`: returned a numbered item ($it.index and $it.item)
## Examples
Echo the square of each integer
```shell
> for x in [1 2 3] { $x * $x }
```
Work with elements of a range
```shell
> for $x in 1..3 { $x }
```
Number each item and echo a message
```shell
> for $it in ['bob' 'fred'] --numbered { $"($it.index) is ($it.item)" }
```