---
title: each while
categories: |
filters
version: 0.104.0
filters: |
Run a closure on each row of the input list until a null is found, then create a new list with the results.
usage: |
Run a closure on each row of the input list until a null is found, then create a new list with the results.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->
# `each while` for [filters](/commands/categories/filters.md)
<div class='command-title'>Run a closure on each row of the input list until a null is found, then create a new list with the results.</div>
## Signature
```> each while {flags} (closure)```
## Parameters
- `closure`: The closure to run.
## Input/output types:
| input | output |
| --------- | --------- |
| list\<any\> | list\<any\> |
## Examples
Produces a list of each element before the 3, doubled
```nu
> [1 2 3 2 1] | each while {|e| if $e < 3 { $e * 2 } }
╭───┬───╮
│ 0 │ 2 │
│ 1 │ 4 │
╰───┴───╯
```
Output elements until reaching 'stop'
```nu
> [1 2 stop 3 4] | each while {|e| if $e != 'stop' { $"Output: ($e)" } }
╭───┬───────────╮
│ 0 │ Output: 1 │
│ 1 │ Output: 2 │
╰───┴───────────╯
```
Iterate over each element, printing the matching value and its index
```nu
> [1 2 3] | enumerate | each while {|e| if $e.item < 2 { $"value ($e.item) at ($e.index)!"} }
╭───┬───────────────╮
│ 0 │ value 1 at 0! │
╰───┴───────────────╯
```