Menu

Post image 1
Post image 2
Post image 3
Post image 4
1 / 4
0

JavaScript While Loop

DEV Community: ai·Karthick (k)·3 months ago
#wR1ivuF4
#dev#loop#javascript#statement#condition#long
Reading 0:00
15s threshold
Cover image for JavaScript While Loop

Karthick (k)

Introduction to the JavaScript while loop statement

The while loop executes a block of code as long as a specified condition is true. In JavaScript, this loop evaluates the condition before each iteration and continues running as long as the condition remains true.

Syntax:

while (expression) {
// statement
}

Basic JavaScript while loop example

The following example uses the while statement to output the odd numbers between 1 and 10 to the console:

Read More