llkafm.blogg.se

While loop js
While loop js











To check this, we can set a variable to 0. Once this block is run, then it will be tested as a normal while loop.

while loop js

Thus, the statements are run without being tested for the condition. This example will output the following to the web browser console log: 1 - Inside while loop on Ģ - Inside while loop on TechOnTheNet.The above syntax clearly signifies that the set of statements placed in a do block will be executed once before the condition is satisfied. Once the counter is 3, the while loop will terminate even though the while loop's condition is set to (counter <= 5). In this while loop example, the break statement is used to exit the while loop early when the counter is equal to 3. Let's look at an example of how to terminate a while loop early using the break statement.Ĭonsole.log(counter + ' - Inside while loop on ') Ĭonsole.log(counter + ' - Done while loop on ') You can also use the break statement to terminate a loop early in JavaScript. This example will output the following to the web browser console log: TechOnTheNet JavaScript How to use the Break Statement with the While Loop In this switch statement example, the break statement is used to terminate the switch statement so that once a match is found no further values are not evaluated. This is the most common use of the break statement.įor example: // Set the TechOnTheNet technology to JavaScriptĬonsole.log('Other TechOnTheNet technologies')

while loop js

You can use the break statement with the switch statement. How to use the Break Statement with the Switch Statement

while loop js

Let's look at an example that shows how to use a break statement in JavaScript.













While loop js