‫Welcome back.
‫In this video, we'll learn about the conditional statements in Java.
‫Conditional statements allow you to make decisions in your code based on certain conditions.
‫They help your program choose different paths and execute specific blocks of code depending on whether
‫a condition is true or false.
‫Let's start with the first type of conditional statements, which is the if statement.
‫The if statement is the simplest form of conditional statements.
‫It checks a condition.
‫And if the condition is true, it executes a specific block of code.
‫For example, int age equal to 15 or 18.
‫Let's start with the if statement to check if age greater than or equal to 18, then I'll print system
‫dot out dot print Ln you're an adult.
‫I'm checking here if this condition between these parentheses.
‫If the condition is true, go and get the age.
‫Compare it to 18.
‫If it is greater than or equal, then print this.
‫If it is not, then skip this code block.
‫Let's run.
‫So we have the message printed out.
‫You're an adult because this age is greater than 18.
‫So we need to execute this System.out.println line.
‫Let me.
‫Start with age equal to 15.
‫Run it again.
‫And you can see there is no message telling us that you are an adult because age is 15.
‫The compiler will get the age value 15, compare it to 18 greater than or equal 18.
‫No, this condition is false.
‫So go and skip everything between these curly braces.
‫So this if condition and the if statement will not be executed.
‫The second type of conditional statements is the if else statement.
‫Consider this code.
‫If I need to print another message telling that the user is a minor, not an adult.
‫So here I start with else keyword and here.
‫I'll make System.out.println.
‫Your.
‫Uh, minor.
‫Okay, let me run.
‫And you can see that the message telling us you're a miner.
‫In this example, if the value of the variable age is greater than or equal to 18, the message you're
‫an adult will be printed out.
‫Otherwise, if the condition is false.
‫Age is less than 18.
‫The message you're a minor will be printed.
‫If there is more condition to be checked, we need to use and between the if and else conditions we
‫need to use.
‫Else if.
‫We'll check for another condition.
‫So I am checking if the age is equal equal to 18 or like for example, 60.
‫I'll print out a message telling the user that is you'll get the message aged person.
‫Let me run here.
‫We get you're a minor.
‫So this example will check if the age is greater than 18.
‫If it is not and this is the case because age is 15, it will skip this block of code.
‫Then it will move to the next condition, which is else.
‫If if the age is equal to 60, 15 is equal to 60, no.
‫So it will skip this code or this block of code else if these two conditions or the all if and else
‫if conditions are false, the else block of code will be executed.
‫So for that we'll get your in minor.
‫Let's try the age is 40 run.
‫And you'll get you're an adult.
‫Because it's checking the age 4040 meets the condition.
‫It will print out this and will not execute these codes.