JS Control Flow
In the name of Allah the most merciful and the most gracious.
My name is Ahmadullah and I am a web developer in this article I am going to teach you about JavaScript Control Flow which is very important in programming.
In javascript we have if, if…else and if…else if statements that can add our logic into our program.
Here is the demo or the pseudo code of my claim.
In the if part just we have one condition which is called if statement. For example:
If Statement
in this image if number is equal to 5 then the condition is true and the following text is going to be displayed into console.
And if the number is not equal to 5 nothing is going to be displayed into console. like the following image.
Now number is equal to 10 and our condition is false because of this nothing won’t be displayed into console.
In the second phase of decision making we have else keyword which tells if our condition is not correct then skip all the conditions and execute the else part of condition. as we saw in the above image and now the result is such below:
If you look at the above image the else phase of our condition is executed because my number is not equal to 5 if it were then the if phase of our condition will be executed.
If…else…if Statement
In this phase we made our logic a little bit complicated by adding else if statement. And now we can put many and many more condition to check whether our condition is correct or not. like below image:
Let’s recap we learnt in this article.
In this article you learnt JavaScript control flow which is one of the more crucial part of every programming language. now you can add your own logic into your program to create massive complicated and logical program.