Hi, welcome to this new video. Now that we understand the concept of Boolean logic, we will be able to dive into conditional statements. Conditional statements, it's one of the most powerful tools that you will learn within programming because it's going to be so useful in so many different circumstances. Let's try to see the syntax. A conditional basically stands by some code block, let's call it, a piece of code that would only be executed if a Boolean statement is true. Then we would consider that the condition. Let's look at the syntax on the right. We have an if, which is a keyword using an if statement to evaluate a first condition, and then we have a code block that only gets executed if that is true. In addition to that if statement, we have two extra keywords that we can use in conjunction with the if. Let's look at the bottom one first, which is else, so basically you have an if statement and then you say, well, if this is true, I execute this else. Meaning if it's not true, I can execute a different block of code. It might happen that sometimes you have more than one condition, maybe you're evaluating a range of numbers and you're evaluating between 0 and 10 and then you want to evaluate also between 10 and 20, and then everything else perhaps falls into the else. Well, then in that case you have what would be an else if or an l if here in Python. We can actually have a second condition where we specify is this number within perhaps the second range and then we have our second block. Let's just try to understand this a little bit more conceptually with this diagram. If statements could be diagram in all interesting ways, but we are actually kind of starting to branch what our code would do. There are certain parts of the code that might never trigger just because maybe we're evaluating a value that it never matches a condition. We could start thinking that certain blocks of code get executed more than others and as we go through the running of the code, we're taking these different paths to conclude our algorithm. But that gives a lot of flexibility to the way we're writing code. We're actually considering a series of scenarios. We're considering a variable response to the data that we're having. Let's see how we can actually implement this into our programming environment. Here we are yet again with our template. Let's bring this back to a bigger screen. This time we're going to try to do something a little bit more graphic because we haven't been using too much of the dynamic capabilities of processing. I wanted to start bringing more animation into videos. Let's start by creating a simple sphere that would move in our screen. Let's create a variable called x that will start at zero. We haven't talked about this too much, and we're going to dive this a little bit more. But whenever we have a variable like this one that it's actually declared outside a function, if we want to use it within this function like draw, we have to use the keyword global. Just to say that within this function we can use x. But x is not a new variable that only exists within this function. But it's actually this variable up here that we declared globally. Let's do an ellipse that starts in the position x, and we are going to do it at 300, 50, 50. It's a simple ellipse and because we're actually working in the draw loop, meaning that this is x. Updating every frame, we could say x+ =1, meaning that to your value, add one. This is the same to say x = x+1. That's the longer way of writing it. I like the +=1 because we could actually change it for a higher value like two or three. Basically, we're incrementing whatever the value of x is 1 every frame. Let's make sure also that the feel of the sphere is wide and we have no stroke. Some graphic here. We're having an issue, let's see. I think we just missing a background. Is that what's happening? There we go. As you can see, we actually have a sphere or a circle, in this case, in our central screen. It's just moving towards the right. This is, as we have seen before, an illusion because we're actually redrawing the background, we're just drawing the circle in different locations in the frame, but we create that illusion of movement. What I want to do is start to use the conditional statement. Let's evaluate here just up to the noStroke. Let's create a little bit of room to work here. Let's say if the value of x is bigger than 200, something would happen. This piece of code would only execute if the value of x is bigger than 200. Let's just change the color for now. Let's say 255,0,0. This would be a red ellipse. Then I can go back to my first indentation and we're going to say else just to re-declare that. Otherwise, if it's not over 200, let's say if it's smaller than 200, the fill it's going to be white. You're going to insist on making this ellipse a white color until we cross the line of 200. Let's see if this works. We have the sphere, it's x condition as you can see at some point, this is the 200-pixel mark. We actually switch the sphere to a different color. We transition not gradually, but instantly. Basically, before we cross those 200 pixels, we're executing this part of the code and once we cross those pixels, if you want to just visualize this a little bit more clearly, you can always do something like a line that is 200,0,200,600, and then this would have a stroke of 255. This would be basically a simple representation of where are those 200 pixels so that you can see that, in fact, that's the point in which the ellipse crosses through that threshold. But let's imagine that we want these ellipse to be only red between 200 pixels and 400 pixels. In our normal English language, we would be able to say, well, x needs to be bigger than 200 and smaller than, let's say 400. We do have something like that which is an AND statement. AND allows us to do a second Boolean condition, and both of those conditions need to be met in order for that to be true. Let's say x smaller than 400. Here, we're creating a range between 200 and 400. Both of those conditions need to be true because we're using the AND. There's also an OR operator in case you wanted to use an OR statement, but we'll see those later. But in this case, bigger than 200 and smaller than 400, it gives us a very clear range. Let's just also draw another line so that we can visualize those 400 pixels and see if in fact this statement is doing what we wanted to do. Let's press "Play". We have 200 pixels here, 400 pixels here. We switch to red, and then we go back to white. Everything outside this area here falls into the L statement because the Ls captures everything that is false. The condition that is true, it's only this condition between 200 and 400. Again, Boolean logic can get very interesting and more advanced certainly as you start building more complex If statements. It's a really good way to altering the way your code executes based on the conditions that you're facing. We'll continue using this If statement in future videos. I'll see you in the next one.