Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

for for core

Loop over a range.

Signature

> for {flags} (var_name) (range) (block)

Parameters

  • var_name: Name of the looping variable.
  • range: Range of the loop.
  • block: The block to run.

Input/output types:

inputoutput
nothingnothing

Examples

Print the square of each integer

> for x in [1 2 3] { print ($x * $x) }

Work with elements of a range

> for $x in 1..3 { print $x }

Number each item and print a message

> for $it in (['bob' 'fred'] | enumerate) { 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