Now that we’ve covered looping, we can repeat whatever we do. Thus, today we cover conditionals, so as to be able to choose when we do it.
We all know this, so let’s jump into code:
julia> x=1;y=2;z=3;if x<y
println("first")
elseif y<z
println("second")
else
println("default")
end
Just a reminder, the indentation is immaterial. And again, as per usual, elseif
and else
blocks are optional.
We can write an if loop in one-line as:
julia> x==y ? println("ok") : println("no")
Alas, that’s too tedious, because its Julia we’re in, we can do a more succinct version:
julia> println(x==y ? "equal" : "unequal")
And of course you can chain ternary operators.
julia> println(x<y ? "x" : y<z ? "y" : "z")#Finding the least valued variable
And that’s it for today! Next up, we discuss a truly distinguishing feature of Julia, the way it deals with arrays.
In this tutorial, we will focus on MapReduce Algorithm, its working, example, Word Count Problem,…
Learn how to use Pyomo Packare to solve linear programming problems. In recent years, with…
In today's rapidly evolving technological landscape, machine learning has emerged as a transformative discipline, revolutionizing…
Analyze employee churn, Why employees are leaving the company, and How to predict, who will…
Airflow operators are core components of any workflow defined in airflow. The operator represents a…
Machine Learning Operations (MLOps) is a multi-disciplinary field that combines machine learning and software development…