for for core
Loop over a range.
Signature
> for {flags} (var_name) (range) (block)
Flags
-
--numbered, -n: return a numbered item ($it.index and $it.item)
Parameters
-
var_name: name of the looping variable -
range: range of the loop -
block: the block to run
Input/output types:
| input | output |
|---|---|
| nothing | nothing |
Examples
Echo the square of each integer
>forxin [123] { print ($x*$x) }
Work with elements of a range
>for$xin1..3 { print$x }
Number each item and echo a message
>for$itin ['bob''fred'] --numbered { print$"($it.index) is ($it.item)" }
Notes
This command is a parser keyword. For details, check: https://www.nushell.sh/book/thinking_in_nu.html
Copyright © 2019–2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/for.html