Skip to content

docs(tutor): add for/loop tutorial - #19644

Merged
fdncred merged 3 commits into
nushell:mainfrom
wantJoy1:feat/tutor-for-loop
Nov 24, 2026
Merged

fdncred merged 3 commits into
nushell:mainfrom
wantJoy1:feat/tutor-for-loop

Conversation

@wantJoy1

Copy link
Copy Markdown
Contributor

Description

Adds an introductory tutor for topic (aliases: loop, loops, while, break, continue). Following tutor conditional, it groups loop constructs into a single topic and focuses on for vs each rather than serving as a full reference.

User-facing changes (Release notes)

Added a tutor for tutorial covering for, loop, while, break, and continue.

Additional notes

Adds a `tutor for` topic (aliases: `loop`, `loops`, `while`, `break`, `continue`) introducing Nushell loops and contrasting `for` with `each`.

Part of nushell#18895
@wantJoy1
wantJoy1 marked this pull request as ready for review November 23, 2026 14:57
@fdncred

fdncred commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Please merge main to fix the ci error

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟢 Looks good, one nit

I ran every example in the new topic on eafb99b and each prints what the text says: 1..3 gives 1 2 3, the continue loop gives 1 3 5, the loop counter stops at 3, and break/continue inside each, where and do fail with nu::compile::not_in_a_loop, as the tutorial says they will. tutor for and its five aliases all open the topic, and tutor list shows for after conditional. One nit about reaching the new topic from the other ones.

Findings: 0 High severity · 0 Medium severity · 1 Low severity

Open (1)

Notes from my clanker, checked on eafb99b. Built the branch and ran tutor for, its five aliases, tutor list, tutor --find, and each code block from the tutorial on the branch binary and on main 1dc849d. cargo fmt --all --check and typos are clean, and CI's lint jobs passed on this head. Didn't run the test suite locally; the root jobs were still running when I checked.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low severity No other topic points to tutor for

tutor blocks already says blocks are used "with loops like while and for" and shows a while loop, but neither it nor tutor each points to the new topic. The new topic links to tutor each, but nothing links back to it. Right now you only find it through tutor list or tutor --find.

On eafb99b:

tutor blocks | ansi strip | str contains 'tutor for'
# false
tutor each | ansi strip | str contains 'tutor for'
# false

A short pointer at the end of block_tutor(), in the same form the other topics use, would fix it:

You can learn more about loops by running:
```
tutor for
```

The same lines would fit in each_tutor() next to the tutor closures pointer. Fine as a follow-up if you'd rather keep this PR to the new topic.

Blocks can also be used with loops like `while` and `for`:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added links to tutor for in block_tutor() and each_tutor() in 2f30e49, thanks!

@fdncred fdncred added category:documentation issues relating to documentation notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section labels Nov 24, 2026
@fdncred
fdncred merged commit 627df5f into nushell:main Nov 24, 2026
14 checks passed
@fdncred

fdncred commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.118.0 milestone Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category:documentation issues relating to documentation notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants