3 Julia Programming: Conditionals, Loops and Functions
This chapter covers
- Creating compound expressions
- Writing if-else statements and loops
- Using short circuit evaluation for inline conditionals
- Writing functions
- Defining methods for functions and structs
In the previous chapter we have seen the building blocks of Julia. We have seen how to define variables as well as basic data types and operations in Julia. We have also seen the data structures to work with collections of data.
In this chapter we will take one more step and learn about the decision logic in Julia. We will also see how to define and work with functions. Multiple dispatch and constructors are important and strong features of Julia and knowing how to use them will save you significant time and effort in the future. I strongly suggest to learn and apply these methods in your future work.
A computer program completes the tasks in one or a combination of several ways.
- Completing the tasks in the given order.
- Choosing the tasks to be completed based on predefined conditions.
- Executing the given tasks until certain conditions are met.
In the first one the code is executed line by line. In the second case, we use a conditional which is known as if-else statement. In the final case, we use loops. In Julia there are for and while loops.