ternary operator
This commit is contained in:
8
ch02.jl
8
ch02.jl
@@ -135,6 +135,14 @@ end
|
|||||||
|
|
||||||
# Code showing ternary operator
|
# Code showing ternary operator
|
||||||
|
|
||||||
|
x > 0 ? sqrt(x) : sqrt(-x)
|
||||||
|
|
||||||
|
if x > 0
|
||||||
|
sqrt(x)
|
||||||
|
else
|
||||||
|
sqrt(-x)
|
||||||
|
end
|
||||||
|
|
||||||
x = -7
|
x = -7
|
||||||
x > 0 ? println("x is positive") : println("x is not positive")
|
x > 0 ? println("x is positive") : println("x is not positive")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user