show-notice
hide-notice

Wednesday, 7 August 2013

For Loop in Javascript


Introduction:

We learned in the previous lesson that "loops" enable your program to continuously execute a block of code for a given number of times, or while a given condition is true.In that lesson, we saw that the While loop executes code while a condition is true.In this lesson, we will see that the JavaScript For loop executes code for a specified number of times.Therefore, we could rewrite the example from the previous lesson to use a for loop.



Example:
<script type="text/javascript">
<!--
var myBankBalance = 0;

for (myBankBalance = 0; myBankBalance <= 10; myBankBalance++) {
document.write("My bank balance is $" + myBankBalance + "<br />");
}
//-->
</script>

SHARE THIS POST   

0 comments :

Post a Comment

Design by Gohilinfotech | www.gohilinfotech.blogspot.com