8. JavaScript Tutorial | Control Statements | Theory

Share this post on:

hey what’s going on guys thermal for telesco learnings and in this quick short theory video which is going to be talking about contro  statements or flow control in JavaScript so if you’re an absolute beginner then you can just glance through this and if you already know what are control statements that is the theory part we can always skip this video and move on to the next one but this is just for the absolute big nose and it’s going to be a very short video so you might as well just glance through it so a little bit of theory on JavaScript control statements so these control statements basically govern the execution flow of the program so what do I mean by this so as you can see on the screen in the blue code typically this is what happens let’s say we have the JavaScript code inside a script tag okay so this is our script tag what happens is the execution starts from line number one that is code statement 1 and then it moves on to the line number 2 then line number 3 and so on and so forth so this is how the basic execution flow goes however in real time or in real-world scenarios this entire flow is not as

simple as in this case okay it does not want to be like a linear way in which the code is going to flow in one direction so this is where the control statements come into the picture and they basically govern how the flow of the program is going to be and how the code statements are going to be executed one after another so why do we need these control statements now let’s say you have your program and you are running your program so your JavaScript code is running and let’s say you are one line number 3, okay your program has reached

line number 3 and now what is happening is you want to perform this statement that is whatever instruction is there in this statement 100 times okay let’s say you want to perform this one single statement you have to perform hundred times so, in that case, are you gonna copy B is this statement hundred different times no right it doesn’t seem logical or it’s totally useless right and it is unnecessary work right so what will you do in that case so this is where that control statement comes into the picture and we will talk about that in a minute but let’s take another case so let’s say at line number five you have to decide whether an integer is even number or an odd number okay so let’s say I list it.

when you have a variable and you are storing some value over here let’s say it is five and you have to make a decision whether this variable  s an even number or an odd number it so in that case two cases can happen either it is or it is even rated so this means that there are two different branches and depending upon what the result is you can print or notify that it is an odd number or an even number right so there

are two different ways in which it can go so this is where that branching is happening so again this is another example of flow control or control shipments in JavaScript so in very basic terms this is why we actually need control statements so that you can perform certainactivities n number of times or we can make certain decision-making kind of scenarios wherein we can use these control statements now in JavaScript we basically have two different types of control statements depending upon what activity or what type of flow control we are going to be performing so we have number one that is conditional control statements and number two that is looping or I iterative control statements now we have a third type which is not really having any type but it assists in these control statements so we use these statements that is the break statement and the continue statement so conditional statements as the name suggests are used when we have to make a particular decision or you have different conditions okay so we have if-else statements and we have switch case so this is number one this is number two so we have two different types of conditional control statements and then in looping or ID relative control statements as the name suggests if you want to perform an activity n number of times instead of copy-pasting that statement or that code n number of times we use loops okay so loops are basically piece of four which performs the same activity n number of times with your particular conditions so we have for loop we have while loop we have do-while loop and then we have a different kind of for in loop in JavaScript which basically works

with objects of course we will be looking at each of these different control statements individually in further videos and we will also see the code and examples so this was just a very quick shot theory video on control statements and why we need control statements okay so that’  it for this video guys I just wanted to make this quick theory video and as we progress in this tutorial series in the upcoming videos we will see a lot of videos and control statements we will take a look at them individually and you’ll also see programs related to these control

statements so thanks for watching guys see you guys in the next video peace.

Share this post on:

Leave a Reply