File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -553,6 +553,21 @@ julia> for i = 1:2, j = 3:4
553
553
If this example were rewritten to use a ` for ` keyword for each variable, then the output would
554
554
be different: the second and fourth values would contain ` 0 ` .
555
555
556
+ Multiple containers can be iterated over at the same time in a single ` for ` loop using [ ` zip ` ] ( @ref ) :
557
+
558
+ ``` jldoctest
559
+ julia> for (j, k) in zip([1 2 3], [4 5 6 7])
560
+ println((j,k))
561
+ end
562
+ (1, 4)
563
+ (2, 5)
564
+ (3, 6)
565
+ ```
566
+
567
+ Using [ ` zip ` ] ( @ref ) will create an iterator that is a tuple containing the subiterators for the containers passed to it.
568
+ The ` zip ` iterator will iterate over all subiterators in order, choosing the `` i `` th element of each subiterator in the
569
+ `` i `` th iteration of the ` for ` loop. Once any of the subiterators run out, the ` for ` loop will stop.
570
+
556
571
## Exception Handling
557
572
558
573
When an unexpected condition occurs, a function may be unable to return a reasonable value to
You can’t perform that action at this time.
0 commit comments