關注微信公共號:小程在線
關注CSDN博客:程志偉的博客
1.比較運算符
比較注意的是字符串的比較,它是按照字符的順序進行比較的,它還區分字母的大小寫。
julia> "qiqia" < "qq"
true
julia> "qiqia" < "aa"
false
julia> "WW" < "aa"
true
julia> "ww" < "aa"
false
2.邏輯運算符
&&表示and的意思
julia> a = 50;b=2;c=-8;
julia> (a>5) && (a<100)
true
julia> (b>5) && (b<100)
false
julia> (c>5) && (c<100)
false
||表示當一個條件爲真的時候,就返回true,兩個都爲假的的時候才返回false。
julia> (c>5) || (b<10)
true
julia> (c>5) || (b<1)
false
3.for()循環
julia> s
0
julia> for i = 1:2:10
s += i
println("s= ",s)
end
s= 1
s= 4
s= 9
s= 16
s= 25
4.while()循環
while()循環的結束條件是一個邏輯表達式,當表達式爲True時,循環就會一直執行。
julia> a = 1
1
julia> while a<50
println(a)
global a *= 2
end
1
2
4
8
16
32
5.break()
julia> a = [1,2,3,4,5,6]
for i = 1:length(a)
if a[i] == 4
println(i)
break
end
end
4