Let’s continue our exploration of Julia basics. Previously I talked about for loops and vectorization. Here, we will talk about how to use control flow operators inside Julia.

What are control flow operators?

As the name suggests control flow operators help us shape the flow of the program. You can return from a function, you can break from a loop, you can skip an iteration of the loop with continue.

A simple task

To understand these concepts, we’ll attempt to solve a problem. Nothing better than some hands-on experience, right? Our challenge is as follows:

Given 2 integers (a, b) print the smallest (up to) 5 integers between a and b such that we’re not printing numbers divisible by 3.

For example if a=5 and b=23 we should print the following numbers:

5
7
8
10
11

If a and b are closer to each other we print everything up to b. Here’s another example with a=2 and b=4:

2
4

If you’re a complete newcomer to programming, you might want to check out my FizzBuzz article [LINK] where I explain for loops and the modulo function.

First, we print

In the spirit of doing this step by step, let’s build up our function:

All this does is print every number between a and b inclusive.

Then, we continue

#programming #python #data-science #code #julia

Control flow basics with Julia
1.55 GEEK