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:
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>
0 comments :
Post a Comment