Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

JavaScript:Tutorial, Loops

loop

  • Please log in to reply
4 replies to this topic

#1 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 06 December 2006 - 01:11 PM

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 LoopsWhile Loops
For Loops:-
The For Loops are used in this way

for (something)
{
do something else
}

While Loops:-
The While Loops are used in this way:-

while (something)
{
Do something else
}

Solution:-
Now that you had an idea of the basic usage of the loops here are some practical codes:-

For Loops:-

<SCRIPT LANGUAGE="JavaScript">
var lp=1;
for (lp=0;lp<15;lp++)
{
document.write ("For Loop "+lp+"<BR>");
}
</SCRIPT>
Note: lp is a variable, and until that variable has reached the value of 14 (<15) the loop will go on

While Loops:-

<SCRIPT LANGUAGE="JavaScript">
var lp=0;
while (lp<15)
{
document.write ("While Loop "+lp+"<BR>");
lp++;
}
</SCRIPT>
Note: lp is a variable, and while that variable is <15 the loop will go on

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..
  • 0

#2 Ronin

Ronin

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 302 posts

Posted 07 December 2006 - 06:52 PM

Nice tutorial. I need to learn JavaScript sooner or later and these (the ones that you've been posting) will help a lot!
  • 0

#3 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 08 December 2006 - 02:15 AM

Nice tutorial. I need to learn JavaScript sooner or later and these (the ones that you've been posting) will help a lot!


I'm happy these helped you :) I will be posting more and more.. be sure to see my next tutorial ( will be posted very soon ) on how to break out of a loop... :)
  • 0

#4 castanza88

castanza88

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 13 December 2006 - 06:35 AM

good breakdown of code, and examples...wish more people did that...
  • 0

#5 TcM

TcM

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 7563 posts

Posted 13 December 2006 - 06:53 AM

good breakdown of code, and examples...wish more people did that...


Thanks... for your feedback :)
  • 0





Also tagged with one or more of these keywords: loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download