Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated collections.md from julia to jldoctest #56921 #57796

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions doc/src/base/collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,29 @@
Sequential iteration is implemented by the [`iterate`](@ref) function.
The general `for` loop:

```julia
for i in iter # or "for i = iter"
# body
end
```jldoctest
julia> iter = 1:3
1:3

julia> for i in iter # or "for i = iter"
# body
end
```

is translated into:

```julia
next = iterate(iter)
while next !== nothing
(i, state) = next
# body
next = iterate(iter, state)
end
```jldoctest
julia> iter = 1:3
1:3

julia> next = iterate(iter)
(1,1)

julia> while next !== nothing
(i, state) = next
# body
next = iterate(iter, state)
end
```

The `state` object may be anything, and should be chosen appropriately for each iterable type.
Expand Down