‫Welcome back.
‫In this video, we are going to create a little login system, not really login system, but we're going
‫to use if statements and negative statements.
‫And I'm going to show you a little example which will be similar to your login system.
‫All right.
‫So what we have is a boolean is admin, a boolean is registered, and then we have a string and that's
‫the user name and I'm going to leave that empty.
‫The same with is admin.
‫Well, I need to set a value here.
‫I'm going to initialize that with false and I'm going to initialize is registered with true.
‫All right.
‫So let's create a little program here where we check is the user registered?
‫So if a user is registered, then I want to write something onto the console.
‫So console dot right line and I'm going to write hi there, registered user.
‫And if the user even has a user name, I want to write something.
‫I want to actually write his username.
‫So if username is not equal empty, I want to go ahead and write something like.
‫So I'm going to copy the console right statement here.
‫Hi there.
‫And then the name of the user.
‫So hi there, comma plus username.
‫And if the user is an admin and he's registered or if actually if he is a user with a specific username.
‫So if username is equal to double equals sign or actually here it equals.
‫Edmund.
‫Then we're going to write something like, Hi there, admin.
‫All right.
‫So that's a nested if statement.
‫We have an if statement within an if statement within an if statement.
‫So this one is in that one and that one is in this one.
‫So we have a negative statement and we check multiple conditions.
‫So first of all, we check is the user locked in and then we check his username.
‫If it's not empty, then we write his username and if it is empty, then we don't.
‫So let's change the username and not keep it empty.
‫So I'm going to say username is equal to console dot read line.
‫So I'm going to read the entry of the user and I'm going to store it in username and then a user could
‫potentially enter something like admin, I'm going to make it uncapitalized, so let's just quickly
‫check that.
‫So there we are.
‫And first of all, it well, it doesn't even know what I don't know yet what I should do.
‫So let's quickly write something to the user so he knows what to do.
‫And I'm going to do that with console right line.
‫Please enter your username.
‫Okay, so let's check that out.
‫Please enter your username and I'm just going to use empty quotations and our program closes.
‫Actually we need to add console that read here because we do all this writing but we never actually
‫do some reading, so let's see it again.
‫Please enter your username and I'm going to use empty screen.
‫And he says Hi there, registered users, our user.
‫Hi there, double quotation mark.
‫So even though I entered those two, it says the username is not an empty string because what I enter
‫here is not an empty string, it's actually a string like that.
‫So let me show you.
‫It's actually something like that.
‫So we have the string or the quotation marks and so forth.
‫So let's try again and I'm not going to enter anything.
‫And then it says Hi there, registered user, but it doesn't say hi there username because now the username
‫is actually empty.
‫All right, so now let's try it again.
‫In this case, I'm going to enter my name and the username.
‫All right, it's Dennis.
‫Hi.
‫They're registered users.
‫Hi, Denis or.
‫Hi there, Denis.
‫So now in case I enter admin.
‫Admin are actually non capitalized.
‫Hi there registered user hider admin and hide their admin.
‫So the first admin is the one that I have entered and the second one is this one here.
‫All right.
‫So you can see you have this nested if statement and based on this condition, we run that code and
‫after that we check another condition.
‫And after that we check another condition.
‫What you could do is you could run them all inside of one if statement.
‫So we can get rid of all of those additional if statements, if we simply check that inside of there.
‫So I'm going to.
‫Break here and I'm going to check.
‫Username not equal empty and username
‫equals admin.
‫Now you might wonder what this equals means because we haven't covered it yet.
‫Equals determines whether the instance and another specified string object have the same value.
‫So that means that it checks whatever is inside of username and compares it with that string.
‫All right, so that's how you compare strings.
‫You compare integers differently.
‫So you compare it integers like that.
‫If.
‫INT or actually my int is equal to my end to this is how you compare integers, but for strings you
‫use the equals.
‫So now I am checking if the user is interested in registered.
‫I check his username and I check if he's an admin and if all of that is the case then I run the code
‫in here so I won't need those if statements anymore.
‫And I'm going to get rid of those.
‫Actually, I need that one.
‫And there we are.
‫So now if I run it.
‫Please enter your username and I'm going to enter admin and it says Hi there.
‫Registered User Hi there.
‫Admin.
‫Hi there admin.
‫So that's a different approach and well they both do almost the same thing even though if you have a
‫nested if statement, so if you have an if statement within an F statement, you can run some additional
‫code before running the next statement.
‫Even though that does work, you shouldn't go too deep.
‫So you shouldn't have an if statement within an if statement within an F statement and so forth.
‫It does get confusing at one point.
‫So try to think of the best concept when you do nested if statements and try to find a way to make it
‫more simple to read and even simpler to build.
‫All right.
‫So one more thing.
‫Now we have comparisons with double and but we can have comparisons with or as well.
‫So let's say I want to check if the person is admin or he is registered because in both cases, I simply
‫want to write something like console right line and you are logged in.
‫All right.
‫So even though only one of them is true, this statement here, this whole comparison here is for is
‫true because either is admin has to be true or is registered has to be true.
‫If both are true, this whole statement is true as well.
‫If none of them is true, then the statement is false.
‫So let's run it again.
‫I'm just going to add or enter Dennis and it's just going to say you are logged in, so why doesn't
‫it tell anything else?
‫So why doesn't it check those ones here?
‫Well, that's because I'm not logged in as an admin and I'm not locked or I don't have a username that
‫is empty.
‫So this statement here is not true anymore.
‫But that statement over here or this if statement.
‫Well, that's actually true because it checks am I in admin and let's see.
‫Well, I'm not an admin.
‫Am I registered?
‫Yes, I am.
‫So it's telling me, okay, you're registered and you are logged in.
‫All right.
‫So now you have seen how to create nested if statements and in the next video we are going to have a
‫look at a little challenge.
‫So please go ahead and try to solve the challenge.
‫See you there.