Wednesday 24 February 2016

Julia: for loop

‘for’ loop is used to iterate over a collection, execute some section of code many times.

Syntax
for i in collection
         statement1
         statement2
         ….
         ….
         statement

end

julia> for i in 1:5
           println(i)
       end
1
2
3
4
5

julia> 

julia> for i in 1:5:100
           println(i)
       end
1
6
11
16
21
26
31
36
41
46
51
56
61
66
71
76
81
86
91
96



Previous                                                 Next                                                 Home

No comments:

Post a Comment