Comprehensions And Filter Vs. For and Continue in Julia

Those that have been reading my blog somewhat consistency might recall a short article I wrote a few months ago discussing how I nearly never use traditional for loops when programming Julia. The primary techniques I use to replace these loops are often either mapping or comprehensions. Julia has a rather robust comprehension syntax that makes it incredibly easy to do just about anything inside of a comprehension. Taking a look at some of my code, this code from Olive.jl, it is clear this is a practice I follow most of the time.

I tend to use comprehensions because they are faster than most other techniques in Julia, and with the begin/end syntax seen above, it is also incredibly legible! While it might often be the case that I write something this way, this is not a rule — there are plenty of examples in this very file where I utilize for loops, for example this function:

Visit Now