nushell/crates/nu-command/src/core_commands
WindSoilder 585ab56ea4
in for, loop, while, auto print final value in each iteration (#7433)
# Description

Fixes: #7404 
Fixes: #7402 

## About change
In `eval_block`, all pipelines(or called statements?) result will be
printed except the last one, the last one is returned by `eval_block`
function.

So if we want to print the last statement in eval block, we just need to
print that value.

# User-Facing Changes

### for
```
❯ for _ in 1..2 { echo "a" }
a
a
```

### while
```
❯ mut x = 1; while $x < 3 { $x = $x + 1; echo bb; }
bb
bb
```

### loop
```
❯ mut total = 0; loop {
∙     if $total > 1 {
∙         break
∙     } else {
∙         $total += 1
∙     }
∙     echo 3
∙ }
3
3
```

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
  - `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2022-12-12 05:46:03 +13:00
..
overlay Simplify FILE_PWD setting in 'overlay use' (#7425) 2022-12-10 19:23:55 +02:00
alias.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
ast.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
break_.rs New commands: break, continue, return, and loop (#7230) 2022-11-25 09:39:16 +13:00
commandline.rs Declare input and output types of commands (#6796) 2022-11-10 10:55:05 +13:00
continue_.rs New commands: break, continue, return, and loop (#7230) 2022-11-25 09:39:16 +13:00
debug.rs Declare input and output types of commands (#6796) 2022-11-10 10:55:05 +13:00
def_env.rs Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() (#7412) 2022-12-09 11:37:51 -05:00
def.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
describe.rs Declare input and output types of commands (#6796) 2022-11-10 10:55:05 +13:00
do_.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
echo.rs Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() (#7412) 2022-12-09 11:37:51 -05:00
error_make.rs Protocol: debug_assert!() Span to reflect a valid slice (#6806) 2022-12-03 11:44:12 +02:00
export_alias.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
export_def_env.rs Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() (#7412) 2022-12-09 11:37:51 -05:00
export_def.rs Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() (#7412) 2022-12-09 11:37:51 -05:00
export_extern.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
export_use.rs Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() (#7412) 2022-12-09 11:37:51 -05:00
export.rs Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() (#7412) 2022-12-09 11:37:51 -05:00
extern_.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
for_.rs in for, loop, while, auto print final value in each iteration (#7433) 2022-12-12 05:46:03 +13:00
help_operators.rs ++= appendAssign operator (#7346) (#7354) 2022-12-09 11:20:58 -05:00
help.rs Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() (#7412) 2022-12-09 11:37:51 -05:00
hide_env.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
hide.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
if_.rs Add OneOf shape to fix else (#7385) 2022-12-08 08:58:54 +13:00
ignore.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
let_.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
loop_.rs in for, loop, while, auto print final value in each iteration (#7433) 2022-12-12 05:46:03 +13:00
metadata.rs Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() (#7412) 2022-12-09 11:37:51 -05:00
mod.rs add help operators command (#7254) 2022-11-27 21:03:17 +13:00
module.rs Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() (#7412) 2022-12-09 11:37:51 -05:00
mut_.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
register.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
return_.rs New commands: break, continue, return, and loop (#7230) 2022-11-25 09:39:16 +13:00
try_.rs Improve empty pipelines (#7383) 2022-12-08 07:31:57 +13:00
use_.rs Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() (#7412) 2022-12-09 11:37:51 -05:00
version.rs Reduced LOC by replacing several instances of Value::Int {}, Value::Float{}, Value::Bool {}, and Value::String {} with Value::int(), Value::float(), Value::boolean() and Value::string() (#7412) 2022-12-09 11:37:51 -05:00
while_.rs in for, loop, while, auto print final value in each iteration (#7433) 2022-12-12 05:46:03 +13:00