Friday 17 October 2014

For loop in JavaScript

For Loop: 
<script type="text/javascript">
<!--
var counter;
document.write("Loop Starts" + "<br />");
for(counter= 0; counter< 10; counter++){
  document.write("Current counter: " + counter);
  document.write("<br />");
}
document.write("Loop stopped!");
//-->
</script>
 
This script will produce the below result 
Loop Starts
Current counter: 0
Current counter: 1
Current counter: 2
Current counter: 3
Current counter: 4
Current counter: 5
Current counter: 6
Current counter: 7
Current counter: 8
Current counter: 9
Loop stopped! 

No comments:

Post a Comment