Skip to main content

if Statement

Think you are going to write a js program. And there is a conditional situation that you have to choose one decision out of set of decisions. So you have to use conditional statements as a solution for that problem. It is like this.
Figure 1
So here what happen is if the condition is true the program is execute. But if it is not true it leaves the condition. Let’s take an example, There are two variables x and y. x is 10 and y is 12. So our condition is x==y ? (Does x equals y?)So what happen there is x and y both goes to the first box and then checks does x equals y ???
Then they come to a decision No No. x is not equal to y. So it go with 2nd path and program will end. That’s all.
There is only one condition here. But we can use if for several conditions and also for nested conditions.
Let’s move to an example with all together. Then you will learn all about if else in one program.
                                            




Here you can see lots of if statements. There is if else statement inside another if statement. It is called nested if statement. Also we can use any number of if statements with using key word else.So finally, can you guess the output of previous code? Yes it is here.



                                                            Figure 3

Comments