Saturday, February 4, 2017

Learn Java for Beginner easily ! part 17 : Nested If

What's up Guys ! Welcome back in my Java tutorial series parts season 1. No, I'm just kidding hahaha. So in a couple of tutorials ago, I've thaught you guys about if statement , precisely on Part 9 .
So if you guys still have no idea about what if statement is, go check Part 9 now. I mean like right now.

In this part of tutorial I'm gonna show you guys something called Nested if statements. What is Nested if statements ?  Nested if statements is a bunch of if statements that nesting in one place to determine which code to run based on the match with the value. If you guys are confused, Just look at the picture below.



See ? there are a lot of if and else statements found inside the code above. That's what we called a  nested if .  If you guys want to understand it easier, I suggest to write the code above on your computer then run the program by keep changing the value of the variable. What I mean by keep changing the value is after you run the program, change the value inside the variable so that you guys will understand how this Nested If  works.

After you guys have run the program, I want you guys to look at the output inside the console box underneath your codes. So in this case I will change the value inside variable just like the picture below and look at the result.


See ? as I change the value, the codes that run by Compiler is different and of course that's the reason why the output are different. So here is a simple scheme about how this nested if works.



This kind of codes are gonna very useful for you whenever you want to make a lot of choices with different requirements. I suggest you guys to learn this one more often because it is not as easy as it looks. Sometimes you're gonna feel confuse about where to put the brackets, the condition, or even about using the logical operators .

So that's it guys for now. Thank you guys for visiting my blog, hope you guys enjoy it and see you on the next tutorial. If you guys got something to be asked, please leave a comment below and thank you very much.

Greetings from Programmer !








No comments:

Post a Comment