.f

Thursday, April 25, 2013

How to create a javascript loop

Javascript loops are used to write diferent values with the same funtion.

EXAMPLE .1 

Void: write numbers from 0 to 9

Without loop:

<script type="javascript">
document.write(0+ "<br>");
document.write(1 + "<br>");
document.write(2 + "<br>");
document.write(3 + "<br>");
document.write(4 + "<br>");
document.write(5 + "<br>");

document.write(6 + "<br>");
document.write(7 + "<br>");
document.write(8+ "<br>");
document.write(9+
"<br>");
</script>

Now with a looping function:

<script type="javascript"> 

var x =0;
for (var i=0; i<10; i++)
  {
  x=x + i + "<br>";
  }

 </script>

 

ads

Ditulis Oleh : Unknown Hari: 4:20 AM Kategori:

0 comments:

Post a Comment