1 'For' Loop in JavaScript Thu Mar 22, 2012 7:29 pm
Mr.Joker
Mr. WebArtz
'For' Loop in JavaScript Using the 'For' loop in javascript |
Hey guys, I am Mr.Joker and today I will show you how to use for loop in javascript. So what for we use for loop? We use it in situations when we want to repeat something without typing same code over and over. How is that possible? Well it is . Here is example code:
We have variable x with value of "Welcome to WebArtz.". Then we have for loop. How it works? Inside brackets first we write a value of some integer, we call it always i (most common) and set value to zero. After we do that, we set condition. I said, if i is less then 10 preform this code. So we see i is zero so code will be preformed forever. To stop that we just add i++ which mean that i will increase 0-1-2-3-4-5-6-7... till it get 10 and there it stop. So, I made a condition that some peace of code will be preformed 10 times without writing that code 10 time. Preatty cool, right? There is another example:
|
Notice : These tutorials are copyrighted by WebArtz Forum. You may not publish it on anywhere without written permission from the administrators. |