‫-: Hi. Within this lecture we are going to dive
‫into the If statements,
‫because that's why we have spent so much time
‫on these operands, like greater than, less than or equal to,
‫not equal to, and or.
‫Because most of the time in programming we we're gonna go
‫for if statements.
‫Because most of the time we want to tell
‫to software to do this if something happens,
‫like if X is actually less than Y,
‫then you're gonna do this.
‫But else, if it's not, then you're gonna do that.
‫For example, over here we are gonna check to see
‫if X is actually less than Y.
‫And we have some complicated codes over here
‫but the current value of X is three, Y is four
‫and Zed is five.
‫And over here, beware of the curly braces.
‫Like we have a lot of curly braces right now.
‫And in the If block, I opened a new curly brace
‫and it means it has its own coding block.
‫Now if I write something over here, like Y is bigger, okay,
‫it will run because X is actually less than Y.
‫But this will run only, and only if, X is less than Y.
‫Now, if I change X to be 30, it won't be run as you can see
‫because X is not less than Y anymore.
‫So this will get run, this execution block,
‫this coding block, inside of the curly braces,
‫will only get run if, and only if, the condition holds.
‫That's how we leverage If statements.
‫We write If, and inside of the parenthesis
‫we write the condition, and then we open a coding block
‫and inside of that coding block, we write
‫whatever we want to do, if that condition holds.
‫But if it doesn't hold, it won't get run
‫or it won't be executed no matter what.
‫For example, we could have downloaded something
‫from the internet.
‫We could have added a new animation or something.
‫It really doesn't matter.
‫You don't always have to print, find something out
‫of the log cat.
‫In real world, you control for a statement
‫and if that holds, you do whatever you want to do.
‫So if X is less than Y, we are gonna write, Y is bigger.
‫But what if it doesn't?
‫Maybe I want to have another condition like this,
‫else if maybe Y is less than X. Okay?
‫So if X is less than Y,
‫then I'm gonna print out Y is bigger.
‫So I'm closing the curly braces,
‫after I write system.out.println.
‫And I say else if Y is less than X
‫and I'm going to write this, X is bigger over here.
‫Now if I run this, then I'm gonna see X is bigger.
‫So this is cool.
‫I get to propose a statement and then afterwards
‫I get to say what if it doesn't hold as well?
‫But over here, as you can see
‫maybe we can come up with a point
‫that X is greater than Y and Y is greater than X.
‫But what if they're equal, actually?
‫Maybe we can add something for that as well, like this:
‫X is equal Y.
‫So as you can see, we can add as many
‫else if blocks as we want like this.
‫So let's make them equal.
‫I run this.
‫Here you go.
‫X is equal to Y.
‫Since they're all 30, now they're equal.
‫And we can actually propose something like this as well.
‫We can do an else.
‫So else means if this doesn't hold
‫and if neither of the as ifs do not hold as well,
‫then what's gonna happen?
‫So maybe you have like tens of thousands
‫of conditions over here.
‫Of course it wouldn't be effective, but just imagine
‫that you have a hundred else ifs over here.
‫So if none of them holds
‫then maybe you may want to do something as well.
‫Then you can use else.
‫If nothing holds in this if statement, if control
‫then we are going to print out this.
‫But if something holds, then it will print
‫out only the code inside of the related block. Okay?
‫So in those examples, since X is not less than Y
‫and Y is not less than X, it's printing out X equals Y.
‫So that's it for if statements.
‫It's really looks like we have basic one
‫but we are gonna use this a lot in the Android development.
‫So if you come to this point, very good.
‫Let's stop here and continue within the next lecture.