From the course: Learning Julia
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Loops
- [Instructor] Another very common task in programming involves iterating over multiple items of data in order to process each one. To accomplish this, we use a programming construct called a loop, and in Julia, there are a few different ways to construct loops, and we'll take a look at those in this video. So I'm going to go ahead and open up loops_start in my editor. So let's begin with a basic for loop. So to create a for loop, I use the for keyword, and then I'm going to define a local loop variable. In this case, I'll call it i, and then use the in keyword, and then specify a range. So for a loop that goes from one to 10, and therefore iterates 10 times, I'm going to give it a one, a colon, and a 10 for the range, and then inside the loop, I'll just simply print out whatever the current value of i is. And then I'll use the n keyword to close off my loop. So that's a basic for loop on a range, but you don't need to specify a numerical range. You can supply any iterable object for…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.