Repository navigation
docs(tutor): add for/loop tutorial - #19644
Conversation
Adds a `tutor for` topic (aliases: `loop`, `loops`, `while`, `break`, `continue`) introducing Nushell loops and contrasting `for` with `each`. Part of nushell#18895
|
Please merge main to fix the ci error |
There was a problem hiding this comment.
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
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.
There was a problem hiding this comment.
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'
# falseA 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.
nushell/crates/nu-command/src/misc/tutor.rs
Line 398 in eafb99b
There was a problem hiding this comment.
Added links to tutor for in block_tutor() and each_tutor() in 2f30e49, thanks!
|
Thanks |



Description
Adds an introductory
tutor fortopic (aliases:loop,loops,while,break,continue). Followingtutor conditional, it groups loop constructs into a single topic and focuses onforvseachrather than serving as a full reference.User-facing changes (Release notes)
Added a
tutor fortutorial coveringfor,loop,while,break, andcontinue.Additional notes
tutorwith more tutorials #18895