Book Image

Julia 1.0 Programming - Second Edition

By : Ivo Balbaert
Book Image

Julia 1.0 Programming - Second Edition

By: Ivo Balbaert

Overview of this book

The release of Julia 1.0 is now ready to change the technical world by combining the high productivity and ease of use of Python and R with the lightning-fast speed of C++. Julia 1.0 programming gives you a head start in tackling your numerical and data problems. You will begin by learning how to set up a running Julia platform, before exploring its various built-in types. With the help of practical examples, this book walks you through two important collection types: arrays and matrices. In addition to this, you will be taken through how type conversions and promotions work. In the course of the book, you will be introduced to the homo-iconicity and metaprogramming concepts in Julia. You will understand how Julia provides different ways to interact with an operating system, as well as other languages, and then you'll discover what macros are. Once you have grasped the basics, you’ll study what makes Julia suitable for numerical and scientific computing, and learn about the features provided by Julia. By the end of this book, you will also have learned how to run external programs. This book covers all you need to know about Julia in order to leverage its high speed and efficiency for your applications.
Table of Contents (17 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Repeated evaluation


Julia has a for loop for iterating over a collection or repeating some code a certain number of times. You can use a while loop when the repetition depends on a condition, and you can influence the execution of both loops through break and continue.

for loops

We already encountered the for loop when iterating over the element e of a collection coll (refer to the StringsRanges and Arrays sections in Chapter 2, Variables, Types, and Operations). This takes the following general form:

# code in Chapter 4\repetitions.jl 
for e in coll 
   # body: process(e) executed for every element e in coll 
end

 

 

Here, coll can be a range, a string, an array, or any other iterable collection (for other uses, also refer to Chapter 5, Collection Types). The variable e is not known outside the for loop. When iterating over a numeric range, often = (equal to) is used instead of in:

    for n = 1:10   
       print(n^3)   
    end 

(This code can be a one-liner, but is spread over three lines...