Created
November 8, 2020 19:48
-
-
Save joubertnel/061e517c07a0cbfb3f68490a51e3d6ed to your computer and use it in GitHub Desktop.
multiple nested for loops combined in a single outer loop, forming the cartesian product of the iterables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i = 1:5, j = 1:2 | |
println((i, j)) | |
end | |
# yields: | |
# (1, 1) | |
# (1, 2) | |
# (2, 1) | |
# (2, 2) | |
# (3, 1) | |
# (3, 2) | |
# (4, 1) | |
# (4, 2) | |
# (5, 1) | |
#(5, 2) | |
for i = 1:3, j = 1:5, k = -2:0 | |
println((i, j, k)) | |
end | |
# yields: | |
# (1, 1, -2) | |
# (1, 1, -1) | |
# (1, 1, 0) | |
# (1, 2, -2) | |
# (1, 2, -1) | |
# (1, 2, 0) | |
# (1, 3, -2) | |
# (1, 3, -1) | |
# (1, 3, 0) | |
# (1, 4, -2) | |
# (1, 4, -1) | |
# (1, 4, 0) | |
# (1, 5, -2) | |
# (1, 5, -1) | |
# (1, 5, 0) | |
# (2, 1, -2) | |
# (2, 1, -1) | |
# (2, 1, 0) | |
# (2, 2, -2) | |
# (2, 2, -1) | |
# (2, 2, 0) | |
# (2, 3, -2) | |
# (2, 3, -1) | |
# (2, 3, 0) | |
# (2, 4, -2) | |
# (2, 4, -1) | |
# (2, 4, 0) | |
# (2, 5, -2) | |
# (2, 5, -1) | |
# (2, 5, 0) | |
# (3, 1, -2) | |
# (3, 1, -1) | |
# (3, 1, 0) | |
# (3, 2, -2) | |
# (3, 2, -1) | |
# (3, 2, 0) | |
# (3, 3, -2) | |
# (3, 3, -1) | |
# (3, 3, 0) | |
# (3, 4, -2) | |
# (3, 4, -1) | |
# (3, 4, 0) | |
# (3, 5, -2) | |
# (3, 5, -1) | |
# (3, 5, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment