Conditional evaluation helps break the code into smaller chunks, with each chunk being evaluated based on a certain condition. There are many ways in which such conditions can be imposed and the code can be handled accordingly.
We will be walking you through various methods of conditional code evaluation. But before we go further, we need to familiarize ourselves with compound expressions.
Compound expressions are ways in which we can make sure that a sequence of code gets evaluated in an orderly fashion. Let's have a look at some code:
julia> volume = begin
len = 10
breadth = 20
height = 30
len * breadth * height
end
6000
julia> volume
6000
Here, we have a simple logic implemented in the form of a compound expression. As you can see, the volume is being calculated as the product of all three dimensions, and then assigned back to the variable itself. The syntax being followed is begin ... end
. The begin...