In JavaScript and most different languages, "loops" modify your program to unendingly execute a block of code for a given range of times, or whereas a given condition is true.
The JavaScript whereas loop executes code whereas a condition is true.
For example, you may create your program show a the worth of a counter whereas the count is a smaller amount than or adequate to say, 10.
Exlanation of code:
We started by declaring a variable referred to as "myBankBalance" and setting it to zero
We then opened a minute loop, inserting our condition between brackets. Our condition checks if this price of the myBankBalance variable is a smaller amount than or adequate to ten.
This is followed by code to execute whereas the condition is true. during this case, we tend to area unit merely, outputting this price of myBankBalance, preceded by some text. This code is placed among wavy braces.
We then increment the worth by one.
When the browser reaches the closing wavy brace, if the condition continues to be true, it goes back to the primary wavy brace and executes the code once more. Of course, by now, the myBankBalance variable has been incremented by one. If the condition isn't true (i.e. the variable is larger than 10), it exits from the loop.
No comments:
Post a Comment