ITERATIVE STATEMENTS ( FOR , WHILE ) - JAVA SCRIPT

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in today's session we will discuss about the iterative statements in javascript so what is the meant by a try to statements and what is the use of these iterative statements so here mainly same instructions so whatever the instructions we are writing same instructions can be executed multiple times so we can execute some same set of instructions multiple times and here we'll write some conditions so for all the 82 statements whatever the statements we are using we have to follow the three things one is the loop variable initialization the second one condition the third one loop variable updation so we can we have we need to initialize one loop variable and then we have to write one condition so this condition is meant for terminating this execution okay so as we have discussed now the same instructions can be executed multiple times so after some iterations we have to terminate it that means we have to stop executing the instructions for that termination we'll write this condition so unless i i mean until the condition becomes false okay until the condition becomes false the instructions will be keep on executing okay so for termination we'll write some condition and for every iteration we need to update the loop name so we need to update the loop variable so that the at particular time the condition becomes false so automatically the instructions will be stop executing right so whatever the iterative statements we are using we have to follow these three things so there are mainly two iterative statements we are using that is a for and while for and y so coming to the syntax for the fur for go with the initialization semicolon condition semicolon updation and open the block and close the block and here we have to write the condition statements here we have to write the statements so this is the syntax for formula so this initialization will be executed only once the initialization will be executed only one that means in the first iteration and immediately after initialization happens the condition will be checked so we have to check the condition this is the second step and if the condition becomes true that means here if the condition becomes true the control will enter into this loop okay the control will enter into this loop and it start executing all these statements which are written in for and after completion of all these exe after completion of executing all these statements updation will be done okay updation will be done and after updation again it will check for the condition whether it is true or false if it is true again the control will enter interval it will start executing all the instructions once it it executed all the instructions again updation will be done and again condition it will check for the condition so this initialization will be executed only once at the beginning and then it will check for the condition enter into the loop updation again check the condition enter into the loop update so this will be repeated until this condition becomes false so at particular time after some finite number of executions finite number of iterations so this condition becomes false we have to write like this so if the condition becomes true every time so it will go with the infinite loop okay it will go with the infinite loop so you never stop executing these statements so that's why we have to write the condition so after some iterations this condition becomes false so whenever the condition becomes false automatically the control will come out from the loop the control come out from the loop okay it doesn't enter into the loop so this is the for loop and see we need not follow the same syntax here so we can also write the initialization out or inside okay initialization can be written inside for loop or outside formula inside firm or outside form okay and condition similarly condition condition can be given inside condition can be given inside with break so we can use a break statement okay in order to terminate we can write the break statement and then updation so updation is also used inside of our inside for loop okay in the for loop or inside the form similarly here also initialization can be done in outside the for loop okay outside means above the form okay above for loop or in the for loop or inside the form okay so here like this we can write for semicolon so these two should be done okay two semicolons should be given here okay this is the syntax this is the syntax and you can open the curly braces and you can write the initialization condition and updation here example so initialization sorry condition updation here this is also correct or you can write the initialization here use the for loop write down the condition here give the updation here so this is also cut okay this is also correct syntax so here the syntax is two columns separating the three things that is the initialization condition and ambition so these things can be written in number of cases so i will execute a program showing all these cases don't worry and we'll go with the value so even the while loop also we have to follow these three that is initialization condition and updation so the syntax is y followed by the condition the statements and updation so here we have to write the updation and here we have to go with the initialization initialization so this is the syntax for while this is the syntax part why okay so just uh i will show you how to print the n numbers okay so i will go with the firm i okay is equal to 0 so i am giving some initialization then i less than or equal to 10 condition i plus plus updation go with here some print i print i so in order to print i so we have to go with the anyone that is we are we are having different ways to print the output on the screen right so we can use a inner html we can use right ln or we can use the alert box so whatever thing we can use any one among these three to print i line so automatically for the first iteration i is zero zero will be printed here in the second iteration i becomes so condition so first one i is equal to zero zero less than ten true so print i zero and updation i plus plus that means one one less than is equal to ten true so one will be printed again updation two two less than or equal to ten three four five six seven eight nine and ten ten less than or equal to ten two ten will be printed and updated so eleven level less than or equal to ten fast so automatically the control comes out from the loop so like this we can execute the formula similarly while loop also so go with i is equal to 0 y i less than or equal to 10 y i less than or equal to 10 open and go the print i and i plus plus okay display i n i plus plus means updation so immediately i is equal to 0 0 less than or equal to 10 print i so automatically 0 will be printed and updated i plus plus means updation so i will be updated to 1 so 1 less than or equal to 10 so again true 1 will be printed 2 3 4 5 6 7 8 9 10 when i is equal to 10 10 less than or equal to 10 true 10 will be printed and 10 will be updated to 11 and here 11 i is equal to level 11 less than or equal to 10 it's a false so automatically the controls will come out from the loop so this is how we can work with iterative statements like for and why so just recalling the concept so whatever the iterative statements that means either for loop or while so whatever the iterative statements you are using you need to follow the three things that is initialization condition and updation so these three are very very important these three are very very important so in this thing where we have discussed about the for loop and while so uh i will demonstrate these two iterative statements by executing a small html code so let us move on to the screen hello friends so just now we have seen the syntax for all the iterative statements mainly for looping while so now i will show you the demonstration for this for loop and while loop so for that we will just start writing the html content so let us start with the html tag so in between the html tag we'll write the body and we can write the script inside the body itself okay so first let us give an heading like iterative statements so this is a heading we will get on the page and we will also write some paragraph because where we have to display the output so paragraph id is equal to a result okay and close the paragraph so in between here we will get the result or simply we can go with the h2 right now we will write the script here so inside the script which we need to give the iterative statements so we will print uh the the numbers n numbers right some for that uh we'll first go with the for loop first we have to initialize the value and i less than or equal to 10 i plus plus and inside that will go we'll give some result is equal to or directly we can print here or we'll give some here result plus is equal to i plus space so i will give some space okay for that we give some i using i value and similarly result is equal to some empty string and after the for loop we will print the this one document dot get element by id result result is the id where we have to display the output so inner html is equal to in the result here it is so now we will print here so i will say with this one as it dot html and now will execute this file so that will get the results see you can observe here one two three four five six seven eight nine and ten right so if you place here hundred will get the result with hundred right and if you want to divide each and each i mean 10 numbers in a row we will write some condition here if i mod 10 is equal to equal to 0 then what we have to do we have to do result plus is equal to br br means breakthrough right you can observe here right so for every 10 numbers we'll get will start printing in the second line right so this is how we can demonstrate the for loop so first initialization condition and the updation so for the first time the initialization will be done and immediately it will check for the condition if the condition is true then this complete body of the for loop will be executed and after executing this one again updation will be done and after updation again it will check for the condition that means this initialization will be executed only one time that's a for the first time right next condition if if condition is true it will enter into the loop it will start executing all the statements into the in the for loop and after completion of this execution it will again update the loop variable and again check the condition so this is the happens in the form and now say similarly just replace this for loop with a while loop so in the while loop also we have to use a loop variable so here we'll take some loop variable as i will initialize the loop variable outside the loop so i will initialize here and here instead of writing all these things we'll write simple condition y i less than or equal to 100 right so updation we need to updation so we will update the variable inside the loop we'll update the loop next you can observe the content is here okay and also if you go with the 2 see so for every mod 2 is equal to 0 we will get the break back break room okay after every even number we'll get the break row so we can consider the first line as a odd numbers and the second line as an even numbers right so this is how we can use the while loop so whatever the iterative statements we are using first we need to have one loop variable initialization and then the condition and then the updation so in for loop in for loop syntax we are taking all the things in the single line okay separated with the semicolon initialization semicolon condition semicolon updation but coming to the while loop we can initialize the value outside and we can we have to write the condition and we can update the value inside even in for group also we can write the initialization outside and updation and sign okay so let us check for that so far and this syntax is should be followed right semicolon and i less than or equal to 100 column close see still we are getting the same output we'll change this one so i'm taking again i mod 10 so that 10 numbers will be printed in a single length so you can observe here that change there is no change but here we are using the initialization outside the for loop updation outside inside the formula okay here we are not using all the three statements we are using only condition but we have to separate with the semicolon two semicolons must be there okay so two semicolons must be there right so this is how we can use the iterative statements that is a for loop and while so hope you understood this one so let us stop here and if you are having any doubts regarding these retry two statements feel free to post your doubts in the comment section definitely i will try to clarify all your doubts and if you really understood my session like my session share my session with your friends and don't forget to subscribe to our channel thanks for watching thank you
Info
Channel: Sundeep Saradhi Kanthety
Views: 3,372
Rating: undefined out of 5
Keywords: sundeep, saradhi, kanthety, html, introduction, basics, markup language, static, webpages, web browser, text editor, txt file, extention, .html, .htm, java scripting, dynamic, front pages, tags, html elements, start tag, end tag, html fundamentals, web serevices, hyper text, java script, script tag, head tag, body tag, client side, scripting language, validation, server side, iterative statements, for loop, while loop, loops, loops variable, initialization, updation, condition, break
Id: kHIUcNEF-2s
Channel Id: undefined
Length: 18min 23sec (1103 seconds)
Published: Thu Jan 07 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.