Tutorial by Examples

Basic Syntax Julia's array comprehensions use the following syntax: [expression for element = iterable] Note that as with for loops, all of =, in, and ∈ are accepted for the comprehension. This is roughly equivalent to creating an empty array and using a for loop to push! items to it. result ...
Before the Julia 0.5, there is no way to use conditions inside the array comprehensions. But, it is no longer true. In Julia 0.5 we can use the conditions inside conditions like the following: julia> [x^2 for x in 0:9 if x > 5] 4-element Array{Int64,1}: 36 49 64 81 Source of the ...
Nested for loops may be used to iterate over a number of unique iterables. result = [] for a = iterable_a for b = iterable_b push!(result, expression) end end Similarly, multiple iteration specifications may be supplied to an array comprehension. [expression for a = iterabl...
Generator comprehensions follow a similar format to array comprehensions, but use parentheses () instead of square brackets []. (expression for element = iterable) Such an expression returns a Generator object. julia> (x^2 for x = 1:5) Base.Generator{UnitRange{Int64},##1#2}(#1,1:5) Fun...

Page 1 of 1