I found list comprehension is very useful tool.
Currently I encountered a problem. Say there is an array of 5 integers named TEST. I want to add 1 to randomly selected elements of TEST for 10 times and see if there is a zero in the result.
I can do it in a normal loop, but my question is if I can do it using comprehension?
julia> TEST = zeros(Int,5)
5-element Array{Int64,1}:
0
0
0
0
0
#if I do the following, a error message jumps.
julia> TEST[rand(1:5)] += 1 for i in 1:10
ERROR: syntax: extra token "for" after end of expression
Stacktrace:
[1] top-level scope at REPL[72]:1
[2] include_string(::Function, ::Module, ::String, ::String)
at .\loading.jl:1088
# and if I enclose the expression with (), it returns a generator.
julia> (TEST[rand(1:5)] += 1 for i in 1:10)
Base.Generator{UnitRange{Int64},var"#43#44"}(var"#43#44"(), 1:10)
Please help me out and tell me how to update array elements using comprehension.