Search results
The While Loop. The while loop loops through a block of code as long as a specified condition is true. Syntax. while (condition) { // code block to be executed. } Example. In the following example, the code in the loop will run, over and over again, as long as a variable (i) is less than 10: Example. while (i < 10) { text += "The number is " + i;
- Try It Yourself
The W3Schools online code editor allows you to edit code and...
- JS Functions
W3Schools offers free online tutorials, references and...
- While
The while statement creates a loop (araund a code block)...
- Try It Yourself
The JavaScript while statement creates a loop that executes a block as long as a condition evaluates to true. The following illustrates the syntax of the while statement: while (expression) { // statement} Code language: JavaScript (javascript) The while statement evaluates the expression before each iteration of the loop. If the expression ...
Here are some examples of while loop in JavaScript. Example 1: var count = 0; while (count < 5) { // Condition console.log (count); count++; // updating variable i } Try It. Run Here. Code Explanation: First, the variable count is initialized to 0. Then, before entering the loop condition is checked.
The JavaScript while and do…while loops repeatedly execute a block of code as long as a specified condition is true. In this tutorial, you will learn about the JavaScript while and do…while loops with examples.
1 maj 2024 · The while statement creates a loop that executes a specified statement as long as the test condition evaluates to true. The condition is evaluated before executing the statement.
The while statement creates a loop (araund a code block) that is executed while a condition is true. The loop runs while the condition is true. Otherwise it stops.
16 sty 2021 · The while statement will help you to execute a piece of code repeatedly until you achieve the desired condition. Learn its syntax and use cases in this tutorial.