5.5.6 for repetation statement
The Javascript For loop resembles the for loop you might have seen in many other programming languages. It is used when you need to do a set of operations many times, with an increment of some kind after each run through the block of code.
Syntax:
For (var = startvalue; var<=end value; var=var+increment) { Code to be executed }
Example:
<html> <body> <script type = “text/javascript”> <!— Var linebreak = “<br/>”; Document.write(“For loop code is beginning”); Document.write(linebreak); For (I = 0; i< 5, i++){ document.write (“Counter i=”+i); document.wirte(linebreak); } Document.write (“For loop code is finished!”); </script> </body> </html>
The above for loop starts with i=0 and get executed until the condition i<5; I will increase by 1 each time the loop runs.
Related Posts:
Sign-up for our email newsletter and get free job alerts, current affairs and GK updates regularly.
Subscribe Here (or)
Subscribe Here (or)
Comments RSS Feed
Leave a Reply