 Let's go over question 4 from the Compound Data 1 workshop. So with these questions here, we're using a loop to initialize an array of values regardless of the size of the array. So that note there is just making sure that we don't hard code our loop. And it's making sure that the loop we're using is this one here, where we've got i is 0, i is less than r.length, i++. Because if you know the size of your array, say if I've got an integer array that has 10 items, it may be tempting to say, well, I only want the indexes from 0 to 9, so I'll say less than 10. But it's just good practice to have it as r.lengths. So that's one thing to note there. OK, so for each of these questions, as you can see here, I'm using the same loop, because I know that loop has i representing the array index. It will go through all of the array indexes regardless of the size. And yeah, that's just what I want to use each time. So to do these questions, what we need to do is work out the pattern between the index and the value. Because there's some relationship there, we need to work out what that is to assign a value to i. So if we have a look at 4.1, that one's not too bad. If we have a look at our pattern, we've got when our index is 0, our value is 0. When our index is 1, our value is 1. When our index is 2, our value is 2, and so on. So we can see here that whatever our index is will be whatever our value is. So what we can say is that for each array item at index i, its value is i. So for each of these questions, we are going to try and write our answer in terms of i. You could, as well, if you wanted to have a separate variable x or whatever you want it to be and allocate it x and then plus 1 to x each time. But if you already have a loop variable that there's some relationship between the value and that loop variable, there's no point creating a new one. But of course, if you create a new one, that's OK as well. OK, if we have a look at 4.2, that one's a little tricky out because we can see that it's doing the odd numbers. It's doing the odd numbers here, but it's a little bit harder to get that relationship between i and that number. So when the index is 0, the value is 1. When the index is 1, the value is 3. And then 5. And I'm assuming it's 7 and then 9. So what I need to do is, well, there's two approaches. There's the one I showed you before where I created a new variable and you would just increase it by 2 each time for this case. However, I think we can do it in terms of our i variable. So what we want to do is rewrite each of our values in terms of i. And that just requires a bit of trial and error, try out a formula, see if it works for the rest of the numbers and see what happens. So if I have a look at index 1, how do I turn 1 into 3? Well, I could do 1 times 2 plus 1, that equals 3. So let's see if that formula works for the rest of our numbers. So to turn 2 into 5, 2 times 2 plus 1 works. Turn 3 into 7, 3 times 2 plus 1 works. So it looks like we have our formula here. 4 times 2 plus 1 is 9. Awesome. And of course, this will equal 1. So I got that quite quickly because I've practised this question and I already know what the formula is. So sometimes, especially in exam conditions, it might take a little bit more trial and error to get that formula. You just want to test out, multiplying different values, adding different values and seeing what works. So I can see here I've rewritten all of my values. If we have a look at our i, I've done all of that. Well, those correspond there and everything else is the same, times 2 plus 1. So that means that what we want to do here is for each index i, the value is i times 2 plus 1. Times 2 plus 1. Great. And then of course, an alternative. It's always nice to do it using the loop variable. But I mean, if you really can't see the relationship, you've pressed for time, then you could always do something like this and then say x plus equals 2. That will also give you the same result. You can see this one is a little nicer using the loop variable. Cool. Now 4.3, actually we don't need that. 4.3, when the index is 0, the item is array dot length. When the index is 1, the item is array dot length minus 1. When the index is 2, the value is array dot length minus 2. So you can see here that each value involves array dot length and depending on what your index is will depend on what is being minused away from the array length. So when it's 1, you're taking away 1. When it's 2, you're taking away 2. And although we can't see it, when it's array dot length, when the index is 0, we're minusing 0, but we don't put a minus 0 there. So that's our relationship. Our relationship is r dot length minus i. And then that last one there, 4.4. It's a little trickier to see that one there. And I'll show you a common error that people make with this one. Sort of, I've got when the index is 0, the value is 1. The index is 1, the value is 2. And I've got 4, 8, and I know the last one's 16. So what I've seen a few students do now, and it's quite tempting to do this, but it will have some issues, a relationship they found was that each item was the previous item multiplied by 2. So for index 1, its value is the previous item 1 times 2, which is 2. If we have a look at 3, its value is 8, which is 4 times 2. For index 4, its value is 16, which is 8 times 2. And that's good that you found that relationship. Our only issue is that what happens when we have 0? When we've got i is equal to 0, we're saying array index 0 is equal to array 0 minus 1, which is minus 1, times 2. And this will give you an index out of bounds exception when I run that code, because the index negative 1 doesn't exist. So you want to be really careful with that. And I would advise not doing this question that way, even if you set your first item to be 1, and then started your loop at 1, that it does work. But there's a way to do this using just i and not having a look at the previous item, because this can cause some issues. And sometimes those issues aren't immediately obvious, especially in exam conditions where you don't have processing to use. So there's actually a different relationship here. And it's to do with powers of 2, because I know anything to the power of 0 is 1. 2 to the power of 1 is 2. 2 to the power of 2 is 4, and so on. So that pattern there, my i's are my powers. And it's 2 to the power of i. And if you do something like this, that's not going to work. Processing doesn't recognize that. So what we want to use here is the power function, which is an inbuilt method in processing, an inbuilt function that takes in two parameters. So it's an informed producer. So you pass in a base and a power. So our base is 2, our power is i, and what it outputs or what it returns is a float. And because of that, we've got, because we have an integer array and we're trying to assign a float to an integer, we need to cast this, which is saying, I know this value will output a float, but please convert it to an integer. So that will get that one to work there. There are lots of inbuilt maths functions that you can use on processing.reference, processing.org slash reference, sorry. We've got some calculation methods here that are quite helpful. However, I would not use them, I'd be careful using them in exams because if your question is asking you to design a function that given an array gives you the biggest number in that array, or actually you could use max for that. What situations would you not use it for? Ah, here we, so one of the questions when we did function was, or functions one I think, was create a function that takes the floor of a number. There's already an inbuilt function that does that for us, but if the aim of the question is to design a method yourself, then you want to actually design that yourself, not just use the inbuilt method. So you want to be careful there, but in this situation, it's okay to use pow. And I think that's the last question, awesome.