Skip to content

Commit 15934ed

Browse files
Updated collections.md from julia to jldoctest
1 parent 04922e7 commit 15934ed

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

doc/src/base/collections.md

+21-10
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,32 @@
55
Sequential iteration is implemented by the [`iterate`](@ref) function.
66
The general `for` loop:
77

8-
```julia
9-
for i in iter # or "for i = iter"
10-
# body
11-
end
8+
```jldoctest
9+
julia> for i in 1:3 # or "for i = iter"
10+
println(i)
11+
end
12+
1
13+
2
14+
3
1215
```
1316

1417
is translated into:
1518

1619
```julia
17-
next = iterate(iter)
18-
while next !== nothing
19-
(i, state) = next
20-
# body
21-
next = iterate(iter, state)
22-
end
20+
julia> iter = 1:3
21+
1:3
22+
23+
julia> next = iterate(iter)
24+
(1,1)
25+
26+
julia> while next !== nothing
27+
(i, state) = next
28+
println(i)
29+
next = iterate(iter, state)
30+
end
31+
1
32+
2
33+
3
2334
```
2435

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

0 commit comments

Comments
 (0)