
The Javascript language also has more sophisticated programming mechanisms such as loops. Today we’re going to be discussing the most complex loop, the for loop. If you’re familiar with this loop from other languages, such as PHP, then you’ll feel right at home with the Javascript version.
The for loop allows you to recursively check if an expression is true, and execute a piece of code for each time that it is. The for loop has three parts to it, the beginning – where you set an initial variable that will be incremented with each run, the middle – where you have an expression to be evaluated, and the end – where you increment the variable created in the beginning.
The beginning will only be run once, the middle will be run until it evaluates until true, and the end will be run at the end of every “cycle” (when the middle is true and after the code is executed). Let’s take a look at an example.
[code='javascript']for (x=0; x < 15; x++) {
document.write(x);
}[/code]
Which would write out 01234567891011121314. For loops have the potential to be the most useful loop at your disposal, use it well.





offshore software development
April 28, 2009 11:22 am
Thanks for the useful information. Will be reading more of your IT related blog posts!
lksmth
May 1, 2009 6:32 pm
gr8 information here..thnaks dude