Hello, welcome to the ninth tutorial the swift basic series. And in this problem we are looking at the for loop loops in general allow code to be repeated, repeated helping reduce code. It could be for example, if you have an array of high school that you want to print out the score, then maybe you have only five. And you could easily access a governor Raya score then you'd have five, but you could easily access five of them five lines. But what if you have 100, you'd only do 100 lines. Use in a loop, you can do it within a few line, which is fantastic.
But the benefits of loops go beyond just printing out some values from an array. Let's just open a project. And to do a loop. First of all, we'll actually just put an array we'll call it ice score equals to 100 H 34. five, zero. And to do a for loop you do a keyword for called bracket bracket. And then inside first of all is the part where you declare or initialize the variables, basically, for the iterator of the following will tell you what that means in the moment on the wall, I equals zero.
And then know the condition for when the for loop will run through one eye in less than five. Okay, that's the size of the array. The for loop will keep running and then after each iteration of the loop, i plus plus aka I will equal i plus one, that would be 01234. And inside here, and now we can do our code. But let's let's go over this again. First action, you declare initialized usually your iterator then using that in iterator you put the condition or have to either trade or the last the general convention, and then you put the actual thing that changes the iterator after each iteration.
So what we're going to do is print ln. And here, we're going to put Oh, four slash one and do colon, forward slash, brackets bracket high scores. In here we're going to put on and if we run this now, we have a high score. And if we run it, we've got each high score printed out with only four lines. I'm not said he would only take five nights to print it out in your favor one night, you might think But what if you had 100 100 lines compared to four? I'm pretty sure now you can see the benefits of using for loops.
The brackets for the for loop are not necessary but they read but are recommended that they help maintain the code readability aka the bracket here. But if we run it, it still produces the same result very similar to conditional statements from the previous tutorial, only the bracket but we do recommend them and they help with the code readability that's it for this tutorial. In the next tutorial we're going to look at the for in loop which is very similar to the for loop with a little more basic we stuff is suited towards something like this. If you have any question feel free to message us at support at sound system Korea cake the email will be in the description you can comment on this video or directly message us for a YouTube all the required info source code will also be in the description and as usual, thanks for watching.
Have a nice day.