Introducere în Julia
James Fulton
Climate informatics researcher
is_raining = true# Conditional expression if is_rainingprintln("Better get your coat") end
Better get your coat
is_raining = true# Conditional expression if is_rainingprintln("Better get your coat") end
Better get your coat
is_raining = false
# Conditional expression
if is_raining
println("Better get your coat")
end
is_raining = true if is_raining # This can be many lines of codeprintln("The weather is awful") println("Better get your coat")end # Code below end is always run println("Ready to go")
The weather is awful
Better get your coat
Ready to go
is_raining = false
if is_raining
# This can be many lines of code
println("The weather is awful")
println("Better get your coat")
end
# Code below end is always run
println("Ready to go")
Ready to go
Când plouă:
amount_of_rain = 1.# Use comparison is_raining = amount_of_rain > 0println(is_raining)
true
Când e uscat:
amount_of_rain = 0.# Use comparison is_raining = amount_of_rain > 0println(is_raining)
false
Când plouă:
amount_of_rain = 1.
# Use comparison
is_raining = amount_of_rain > 0
# Conditional expression
if is_raining
println("Better get your coat")
end
Better get your coat
Când e uscat:
amount_of_rain = 0.
# Use comparison
is_raining = amount_of_rain > 0
# Conditional expression
if is_raining
println("Better get your coat")
end
Când plouă:
amount_of_rain = 1.
# Conditional expression
if amount_of_rain>0
println("Better get your coat")
end
Better get your coat
Când e uscat:
amount_of_rain = 0.
# Conditional expression
if amount_of_rain>0
println("Better get your coat")
end
a == b verifică dacă două valori sunt egalea = 1.# Value of a is 1? println(a==1)
true
# Data type of a is Float64?
println(typeof(a)==Float64)
true
a == b verifică dacă două valori sunt egalea != b verifică dacă două valori sunt diferitea = 1.# Value of a is not 1? println(a!=1)
false
# Data type of a is not Float64?
println(typeof(a)!=Float64)
false
a == b verifică dacă două valori sunt egalea != b verifică dacă două valori sunt diferitea > b verifică dacă a este mai mare decât ba >= b verifică dacă este mai mare sau egala = 1.# a is greater than 1? println(a>1)
false
# a is greater than or equal to 1?
println(a>=1)
true
a == b verifică dacă două valori sunt egalea != b verifică dacă două valori sunt diferitea > b verifică dacă a este mai mare decât ba >= b verifică dacă este mai mare sau egala < b verifică dacă a este mai mic decât ba <= b verifică dacă este mai mic sau egala = 1.# a is less than 1? println(a<1)
false
# a is less than or equal to 1?
println(a<=1)
true
amount_of_rain = 0. if amount_of_rain == 0 # Do this if conditon is met println("The sky looks clear")else # Do this if not met println("Better get your coat")end
The sky looks clear
amount_of_rain = 5.
if amount_of_rain == 0
# Do this if conditon is met
println("The sky looks clear")
else
# Do this if not met
println("Better get your coat")
end
Better get your coat
amount_of_rain = 0. if amount_of_rain == 0 println("There is zero rain")elseif amount_of_rain < 1 # Add a second condition println("Better get your coat")else println("That's a lot of rain, stay home") end
There is zero rain
amount_of_rain = 0.5
if amount_of_rain == 0
println("There is zero rain")
elseif amount_of_rain < 1
# Add a second condition
println("Better get your coat")
else
println("That's a lot of rain, stay home")
end
Better get your coat
amount_of_rain = 2
if amount_of_rain == 0
println("There is zero rain")
elseif amount_of_rain < 1
# Add a second condition
println("Better get your coat")
else
println("That's a lot of rain, stay home")
end
That's a lot of rain, stay home
amount_of_rain = 2
if amount_of_rain == 0
println("There is zero rain")
elseif amount_of_rain < 1 # <--- many elseif conditions
println("Better get your coat")
elseif amount_of_rain < 5 # <--- many elseif conditions
println("You're going to need a bigger coat")
else
println("That's a lot of rain, stay home")
end
You're going to need a bigger coat
Introducere în Julia