 So let's have a look at four loops. Now these loops are phenomenal and they almost read like English sentences quite easy to follow along So they are constructed like this. Let's have a look. We have four and end You've got to tell this little loop way to end things and it's going to run around and around This is our little raft running around and around in the river We create inside of this for loop of computer variable and this time I've called it I can call it whatever I like within reason I can't use Julia keywords and Can't use plus or minus signs in between etc But I've called it just I for I in one to five now this one to five note There's no brackets around it. There's no square brackets parentheses around it So that makes this and we look have a look close look at this later. It's just a range object It's just going to go one two three four five Print line we've seen before it's just going to print a single line of text and what it's going to print is inside of These parentheses and at the moment it is the value that's inside of the computer variable called I and then end So we're going to run through this through this through this What this for loop does is it just evaluates? Whatever is there one to five. So when it gets to five, that's what we actually get to to the end of the of the code So the first time it runs through it's I's going to be one It's going to print one it goes run to through it again and because this is just a range object It's going to go to to all automatically you don't have to do anything, but the integer value it jumps by an integer value Let's run the code and you see As you expect one two three four five to the scheme this little tab that you see there Julia does that automatically for you or at least the the notebook here does If you write the four line and you hit enter it does this little places this little tab to keep things nice for you No issue Now have a look at this now this one two five didn't have any brackets around up and I'm putting these square brackets around what happens here and It's these strings these and are and words separated by comma So these are three separate things and they just happen to be strings inside of this these square brackets And I'm saying for word in this print word That's not print line to sprint comma and This backslash t that means that tab. That's just going to leave a bit of space in between We're going to execute this line of code. So you just can you can see what happens. So there's this computer variable called word Each time that runs through it's going to take the one then the next one then next next one as you can see It's these tab are tab words can't see the last tab there now We do this in in teaching computer language by using these words that make sense I just want to show you it doesn't really matter what you call this. I'm going to call it WRT Don't know why this did WRT Doesn't matter. It's not the word word doesn't mean anything It's just a computer variable that I came up with because if I ran this code again Exact same output. So it doesn't matter what it is and this for loop is clever enough to see that these This is a list of things actually called an array and we'll look at these kind of things in the upcoming lecture And it's these three and every time it's going to take one then the next one then the next one the print is this and I didn't say Print line here because I wanted everything on the same line If you just give it one String and there's no brackets around it It's actually going to be clever enough to take each letter on its own again I needn't have written letter there I could have written any computer variable name there with in with it that are within the rules So it's J with a tab you with a tab L with a tab and it just iterates through each of those characters Now I have a look at this now. I'm iterating through something that's in within curly braces So let's see what happens there and I'm calling my variable stuff Just to show you that I can use any word there within the rules So for stuff in this stuff that's inside this curly braces at 10 at 20 the word 30 and the square root of 1600 Print line and I wanted to print stuff So whatever's in that computer variable stuff through that loop Then a tab and then the type of stuff that should be interesting So we can see what 10 20 30 and square root of 1600 are and that's quite nice So the sprint line so each is going to go on a separate line 10 is a 64 bit integer 20 is a 64 bit integer 30 is a string and 40.0 is a 64 bit float Now I want to show you something We created this these computer variables first. I called it word. Let's change it back to word. This looks better It's good to write code so that the code makes sense, but I just wanted to show you it's not the actual word itself So I've created this variable called word you have created a variable called letter You have created a variable called stuff, but it's inside of a for loop Now this is called the scope of a variable. Where does it exist? I just want to show you that if you create a variable inside of a loop like this It does not it ceases to exist outside of the loop Unless unless something I'll tell you what that's something is So yeah, I want to show you that it doesn't exist because I'm gonna say stuff and it's going to return an error Now I don't just say stuff here and hit shift enter Or shift return because I know it's going to cause an error And sometimes you might know that something's going to cause an error But you don't want your code to stop executing because that's what happens when there's an error. It just stops it executing And you don't want that in those cases put it inside of this try catch in statement So try and then try something stuff if I just write the variable It's going to output what that variable is but it doesn't exist It's scope it only exists inside of this for loop If that returns an error, I catch that error and I put the error inside of a variable and yeah, I've called the variable x And I want to print two things I print and to print a line where I tell what is the type of egg the error And then there's this keyword show error in standard output and then the error itself an end So this is a try catch So block of code that I am running and just to show you So print line the type of the error It's an undefined variable error because that variable does not exist It only existed inside the loop once that loop was finished It was wiped from emny And this the show error standard output the error is stuff not defined So it's just a standard way if if ever you have code that you wanted that's not going to execute Place it here. Remember this little block of code. You can this is pretty standard stuff You can always have that in your code and put whatever you you think might not work in there And then the rest of your code can go outside of this Now let let's create stuff and put a string in it I exist If I just put stuff it says I exist there I just put stuff and it threw up an error But I put it inside of this little try catch statement So it's still con if if this happened the code wouldn't stop executing it would carry on Now it exists now that it exists. I'm using it inside of that same 4n loop there. Let's do the same thing So it went 10 20 30 40 with the types of this is that we had before but what is stuff now Does it still not exist does it cease to exist because it was in this? No, it actually doesn't because it existed before it has a scope that lives outside of its scope is I exist outside of this for loop. It is an explicit variable It was explicitly created before this for loop And now if inside of a for loop its value changes as it does first it was I exist then it was 10 and it was 20 then it was 30 then it was a square root of 1600 It will keep the last value that it had as it should So that is just the scope of a variable inside of a for loop Just to show you one more thing about for loops You can nest for loops inside of for loops So I'm running an outside for loop where a just iterates from this range object from one to three Inside of that is another for loop that goes from one to two And then I want it to print line a and b. What do you think it's going to happen? It's going to say a equals one. There's my one b equals one and then prints it to the scheme one and one But it stays within this inner little loop. So now it's going to go one two Before it exits that little loop and goes to the larger outside loops now moves over to two one two two and then three one three two So you can nest many for loops inside of other for loops. So we've learned quite a bit here. We've learned about iterating through a for loop and iterating through different things through a range object through these lists of arrays of texts Through single left through the letters of a single word through these funny stuff. That's all mixed up and jumbled of any type And we've printed to the scheme the type there of We've shown you that the scope of this variable inside of a loop is just internal to that It sees us to exist outside. I showed you how to catch an error So that your program doesn't stop running and a pretty standard output as to what to do to print it to the screen And then to show you if once it exists outside of this its scope is outside of just this little Loop it actually retains that value and then lastly how to nest little four loops inside of bigger loops