Introduction:-
In this tutorial I will show you the two types of loops there are in JavaScript.
Explanation:-
You might say where is the code? He is already explaining without the code?
Well this time I think that its better if the Explanation comes before the Code
There are 2 types of loops:-
- For Loops
- While Loops
For Loops:-
The For Loops are used in this way
While Loops:-Code:for (something) { do something else }
The While Loops are used in this way:-
Solution:-Code:while (something) { Do something else }
Now that you had an idea of the basic usage of the loops here are some practical codes:-
For Loops:-
Note: lp is a variable, and until that variable has reached the value of 14 (<15) the loop will go onCode:<SCRIPT LANGUAGE="JavaScript"> var lp=1; for (lp=0;lp<15;lp++) { document.write ("For Loop "+lp+"<BR>"); } </SCRIPT>
While Loops:-
Note: lp is a variable, and while that variable is <15 the loop will go onCode:<SCRIPT LANGUAGE="JavaScript"> var lp=0; while (lp<15) { document.write ("While Loop "+lp+"<BR>"); lp++; } </SCRIPT>
A Preview:-
None
Conclusion:-
As Always Feedback is welcome! In the next tutorial I will tell you how to exit from the loop. I don't think that this needs any source code..
Last edited by TcM; 12-06-2006 at 01:14 PM.
Nice tutorial. I need to learn JavaScript sooner or later and these (the ones that you've been posting) will help a lot!
good breakdown of code, and examples...wish more people did that...
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks