x = Inf
if x<1
@printf("x is smaller than 1");
end
x = 1.5
if x<1
println("x is smaller than 1")
else
println("x is larger than or equal to 1")
end
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 = -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
# 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
# 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
x = 0
y = 5
if x+y > 10 || x < 0
y = 0
else
y = 10
end
for i=1:10
@show i
println("end loop iteration")
end
v = 1:10
for i in v
@show i
println("end loop iteration")
end
# There is no difference between "=" in a loop and "in"
v = 1:10
for i=v
@show i
println("end loop iteration")
end
v[5] = 10. # v isn't really a vector!
x = collect(v) # turn this into a vector
x[5] = 10.
@show x
for i=x
@show i
println("end loop iteration")
end
# this is very different from Matlab now!
@show [v' v'+1]
for i=[v' v'+1] #
@show i
end
@show [x x+1]
for i=[x x+1] #
@show i
end
@show [x'; x'+1]
for i=[x'; x'+1] #
@show i
end
# we proceed through the array in column-wise order
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