Follow us on Twitter!
Become the change you seek in the world. - Gandhi
Thursday, April 24, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 29
Guests Online: 23
Members Online: 6

Registered Members: 82895
Newest Member: kevy90
Latest Articles

Javascript Loops

Arrow Image Crash course on Javascript Loops



Loops in Javascript by RockBll4

First of all this is my second first article, so dont be too harsh.

Well I know some Javascript and I thought I'd do a little article on Loops.

So the loops in javascript are: the for loop and the while loop.




THE FOR LOOP:

The for loop is used when you know in advance how many times the script should run.

the syntax for the for loops is as follow:


for ( var = value; var <= endvalue; var(increment) )
{
code to be executed within the code block
}



Example:

<html>
<head>Javascript for Loop Example</head>
<body>

<script type="text/javascript" language="Javascript">
<!--

var i = 1;

for ( i = 1; i <= 5; i++ )
{
docu<i></i>ment.write("Hi " + i + " times");
docu<i></i>ment.write("<br/>");
}

//-->
</script>

</body>
</html>


Result:

Hi 1 times
Hi 2 times
Hi 3 times
Hi 4 times
Hi 5 times





THE WHILE LOOP:

The while loop is used when you want the loop to execute and continue executing while the specified condition is true.

the syntax for the while loop is:

while ( var <= endvalue)
{
Code to be executed within the code block
var(increment);
}



Example:

<html>
<head>Javascript while Loop Example</head>
<body>

<script type="text/javascript" language="Javascript">
<!--

var i = 1;

while ( i <= 5 )
{
docu<i></i>ment.write("Hello " + i + " times.");
docu<i></i>ment.write("<br/>");

i++
}

//-->
</script>

</body>
</html>


Result:

Hello 1 times.
Hello 2 times.
Hello 3 times.
Hello 4 times.
Hello 5 times.






There is your crash course on the loops in Javascript.

If you would like to further your understanding on loops or Javascript go to google and do some research ;-).

Comments

H-oLm35on August 28 2006 - 21:56:41
nice.. this couldd be usefull to change js14 ... using some cookis Grin :ninja: :happy:
n30on August 28 2006 - 22:12:45
js14 is down you know H-oLm35.... anyway, nice article:angry: *gives u 2 thumbs up*. Next time, be aware that it doesn't accept HTML tags:ninja: 4/5
rockbll4on August 28 2006 - 22:47:08
lol ik that it doenst accept html tags, it still emphysizes the main parts tho (if you know html Wink)
chaunchothenachoon June 11 2007 - 06:20:40
it does acccept html...just not after you click on the comments.:ninja:
Post Comment

Sorry.

You must have completed the challenge Basic 1 and have 100 points or more, to be able to post.