🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › while
while - JavaScript - MDN Web Docs - Mozilla
After completing the third pass, the condition n < 3 is no longer true, so the loop terminates. In some cases, it can make sense to use an assignment as a condition. This comes with readability tradeoffs, so there are certain stylistic recommendations that would make the pattern more obvious for everyone. Consider the following example, which iterates over a document's comments, logging them to the console. ... const iterator = document.createNodeIterator(document, NodeFilter.SHOW_COMMENT); let currentNode; while (currentNode = iterator.nextNode()) { console.log(currentNode.textContent.trim()); }
🌐
W3Schools
w3schools.com › jS › js_loop_while.asp
JavaScript While Loop
The while loop loops through a block of code as long as a specified condition is true. while (condition) { // code block to be executed } In the following example, the code in the loop will run, over and over again, as long as a variable (i) ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-while-loop
JavaScript While Loop - GeeksforGeeks
The while loop executes a block ... and continues running as long as the condition remains true. Here's an example that prints from 1 to 5....
Published   September 30, 2025
🌐
Programiz
programiz.com › javascript › while-loop
JavaScript while and do...while Loop (with Examples)
JavaScript for... of Loop ... The while loop repeatedly executes a block of code as long as a specified condition is true.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Loops: while and for
This form of syntax should only be used when you want the body of the loop to execute at least once regardless of the condition being truthy. Usually, the other form is preferred: while(…) {…}. The for loop is more complex, but it’s also the most commonly used loop. ... Let’s learn the meaning of these parts by example.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Loops_and_iteration
Loops and iteration - JavaScript - MDN Web Docs - Mozilla
May 21, 2026 - The first form of the syntax terminates the innermost enclosing loop or switch. The second form of the syntax terminates the specified enclosing labeled statement. The following example iterates through the elements in an array until it finds the index of an element whose value is theValue: ... let x = 0; let z = 0; labelCancelLoops: while (true) { console.log("Outer loops:", x); x += 1; z = 1; while (true) { console.log("Inner loops:", z); z += 1; if (z === 10 && x === 10) { break labelCancelLoops; } else if (z === 10) { break; } } }
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript while loop
JavaScript while Loop By Examples
November 15, 2024 - while (expression) { // statement }Code language: JavaScript (javascript) The while statement evaluates the expression before each iteration of the loop.
🌐
W3Schools
w3schools.com › js › js_looping.asp
JavaScript Loops
The while loop executes a block of code as long as a specified condition evaluates to true. while (condition) { // code block to be executed } In the following example, the code in the loop will run, over and over again, as long as a variable ...
🌐
Mimo
mimo.org › glossary › javascript › while-loops
JavaScript While Loops: Master Iteration | Learn Coding Now
The JavaScript while loop is a control flow statement that runs a block of code for as long as a specified condition is true.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › javascript › javascript_while_loop.htm
JavaScript - While Loops
The purpose of a while loop is ... becomes false, the loop terminates. ... In the example below, we defined the 'count' variable and initialized it with 0....
🌐
TutorialsTeacher
tutorialsteacher.com › javascript › javascript-while-loop
while loop in JavaScript
JavaScript includes while loop to execute code repeatedly till it satisfies a specified condition. Unlike for loop, while loop only requires condition expression. ... Make sure condition expression is appropriate and include increment or decrement counter variables inside the while block to avoid infinite loop. As you can see in the above example, while loop will execute the code block till i < 5 condition turns out to be false.
🌐
Tutorial Republic
tutorialrepublic.com › javascript-tutorial › javascript-loops.php
JavaScript While, Do-While, For and For-In Loops - Tutorial Republic
This is the simplest looping statement provided by JavaScript. The while loop loops through a block of code as long as the specified condition evaluates to true. As soon as the condition fails, the loop is stopped. The generic syntax of the while loop is: ... The following example defines a loop that will continue to run as long as the variable i is less than or equal to 5.
🌐
Medium
medium.com › @francesco-saviano › 10-exercises-with-while-loops-in-javascript-8cfb2bd81a71
10 Exercises with While Loops in JavaScript | by Francesco Saviano | Medium
October 24, 2024 - Write a JavaScript program to calculate ... positive integers less than or equal to that number. For example, the factorial of 5 (5!) is 5 × 4 × 3 × 2 × 1 = 120....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › do...while
do...while - JavaScript - MDN Web Docs - Mozilla
let result = ""; let i = 0; do { i += 1; result += i; } while (i < 5); console.log(result); // Expected output: "12345" ... A statement that is executed at least once and re-executed as long as the condition evaluates to true. You can use a block statement to execute multiple statements.
🌐
Udacity
udacity.com › blog › 2025 › 01 › javascript-loops-explained-for-while-and-do-while-made-simple.html
JavaScript Loops Explained: for, while, and do-while Made Simple | Udacity
January 30, 2025 - In this article, I'll walk you through the main types of loops in JavaScript. We'll look at how each one works, when to use them, and how to choose the right one for your specific needs with examples based on real-world scenarios.
🌐
Medium
medium.com › @rk0936626 › while-loop-in-javascript-d6450ea4b7fc
While Loop in JavaScript.. Loops in JS. | by Ranjan Kumar | Medium
January 10, 2025 - Let’s say you want to keep guessing a number until you guess 7. let guess; while (guess !== 7) { // Keep guessing until the number is 7 guess = Math.floor(Math.random() * 10) + 1; // Guess a number between 1 and 10 console.log("Your guess:", ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › using-while-loops-and-do-while-loops-in-javascript
Using While Loops and Do...While Loops in JavaScript | DigitalOcean
August 26, 2021 - The while statement is the most basic loop to construct in JavaScript. As an example, let’s say we have an aquarium that has a population limit. For each iteration of the loop, we will add one fish.
🌐
Alma Better
almabetter.com › bytes › tutorials › javascript › do-while-for-while-loop-in-javascript
JavaScript for, while, and do-while Loops
June 22, 2023 - Syntax of while loop The while ... in JavaScript that executes a block of code as long as a specified condition is true. The syntax for a while loop is as follows: ... When a while loop is executed, the condition is evaluated before the code block is executed. If the condition is true, the code block is executed. After the code block is executed, the condition is evaluated again. This process continues until the condition becomes false. Examples of while loop ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › loops-in-javascript
JavaScript Loops - GeeksforGeeks
Example: The below JavaScript program while loop prints "Number:" followed by i repeatedly while i is less than 3, incrementing i by 1 each time.
Published   January 19, 2026