13: While Loop

A while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The while loop can be thought of as a repeating if statement.

Syntax:

while (condition) {  
    // code block to be executed 
}

Example:

let i = 0; 
while (i < 10) {  
    console.log(i); // you can test by hardhat console log 
    i++;
}

Output: 0123456789

That's it for the lesson 13! In the next lesson, Do While

Last updated