In [4]:
x = Inf
if x<1
    @printf("x is smaller than 1");
end
In [6]:
x = 1.5
if x<1
    println("x is smaller than 1")
else
    println("x is larger than or equal to 1")
end
x is smaller than 1
In [7]:
x = -5
if x < 1
    println("x is smaller than 1")
elseif x < 0
    println("x is smaller than 0")
else
    println("x is larger than or equal to 1")
end
x is smaller than 1
In [8]:
x = -5
if x < 0
    println("x is smaller than 0")
elseif x < 1
    println("x is smaller than 1")    
else
    println("x is larger than or equal to 1")
end
x is smaller than 0
In [9]:
# this is like Matlab and doesn't work
x = [1. 2]
if all(x >= 0) && all(x <= 5)
    println("all elements between [0,5]")
end
LoadError: MethodError: `isless` has no method matching isless(::Array{Float64,2}, ::Int64)
Closest candidates are:
  isless(!Matched::AbstractFloat, ::Real)
  isless(!Matched::Real, ::Real)
  isless(!Matched::Char, ::Integer)
while loading In[9], in expression starting on line 3

 in >= at operators.jl:37
In [11]:
# this is "Julian" and does work
x = [1, 6]
if all(x .>= 0) && all(x .<= 5) # notice the dots!
    println("all elements between [0,5]")
end
In [16]:
x = 0
y = 5
if x+y > 10 || x < 0
    y = 0
else
    y = 10
end
Out[16]:
10
In [17]:
for i=1:10
    @show i
    println("end loop iteration")
end
i = 1
end loop iteration
i = 2
end loop iteration
i = 3
end loop iteration
i = 4
end loop iteration
i = 5
end loop iteration
i = 6
end loop iteration
i = 7
end loop iteration
i = 8
end loop iteration
i = 9
end loop iteration
i = 10
end loop iteration
In [18]:
v = 1:10
for i in v
    @show i
    println("end loop iteration")
end
i = 1
end loop iteration
i = 2
end loop iteration
i = 3
end loop iteration
i = 4
end loop iteration
i = 5
end loop iteration
i = 6
end loop iteration
i = 7
end loop iteration
i = 8
end loop iteration
i = 9
end loop iteration
i = 10
end loop iteration
In [19]:
# There is no difference between "=" in a loop and "in"
v = 1:10
for i=v
    @show i
    println("end loop iteration")
end
i = 1
end loop iteration
i = 2
end loop iteration
i = 3
end loop iteration
i = 4
end loop iteration
i = 5
end loop iteration
i = 6
end loop iteration
i = 7
end loop iteration
i = 8
end loop iteration
i = 9
end loop iteration
i = 10
end loop iteration
In [20]:
v[5] = 10. # v isn't really a vector!
LoadError: indexed assignment not defined for UnitRange{Int64}
while loading In[20], in expression starting on line 1

 in setindex! at abstractarray.jl:592
In [21]:
x = collect(v) # turn this into a vector
Out[21]:
10-element Array{Int64,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
In [22]:
x[5] = 10.
Out[22]:
10.0
In [24]:
@show x
x = [1,2,3,4,10,6,7,8,9,10]
Out[24]:
10-element Array{Int64,1}:
  1
  2
  3
  4
 10
  6
  7
  8
  9
 10
In [23]:
for i=x
    @show i
    println("end loop iteration")
end
i = 1
end loop iteration
i = 2
end loop iteration
i = 3
end loop iteration
i = 4
end loop iteration
i = 10
end loop iteration
i = 6
end loop iteration
i = 7
end loop iteration
i = 8
end loop iteration
i = 9
end loop iteration
i = 10
end loop iteration
In [ ]:
In [25]:
# this is very different from Matlab now!
@show [v' v'+1]
for i=[v' v'+1] #
    @show i
end
[v' v' + 1] = [1 2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10 11]
i = 1
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
i = 8
i = 9
i = 10
i = 2
i = 3
i = 4
i = 5
i = 6
i = 7
i = 8
i = 9
i = 10
i = 11
In [26]:
@show [x x+1]
for i=[x x+1] #
    @show i
end
[x x + 1] = [1 2
 2 3
 3 4
 4 5
 10 11
 6 7
 7 8
 8 9
 9 10
 10 11]
i = 1
i = 2
i = 3
i = 4
i = 10
i = 6
i = 7
i = 8
i = 9
i = 10
i = 2
i = 3
i = 4
i = 5
i = 11
i = 7
i = 8
i = 9
i = 10
i = 11
In [27]:
@show [x'; x'+1]
for i=[x'; x'+1] #
    @show i
end
# we proceed through the array in column-wise order
[x';x' + 1] = [1 2 3 4 10 6 7 8 9 10
 2 3 4 5 11 7 8 9 10 11]
i = 1
i = 2
i = 2
i = 3
i = 3
i = 4
i = 4
i = 5
i = 10
i = 11
i = 6
i = 7
i = 7
i = 8
i = 8
i = 9
i = 9
i = 10
i = 10
i = 11
In [30]:
i = 0;
while i < 10
    if i == 5
        break
    end
    if i == 4
        #i = i+5 # comment out this line at your own risk!
        continue
    end
    i = i+1
end
@show i
LoadError: InterruptException:
while loading In[30], in expression starting on line 2

 [inlined code] from In[30]:10
 in anonymous at no file:0