How to use Repeated Statements
Describes how JavaScript uses repetitive statements.
In JavaScript, you can use repetitive statements such as for, for β¦ in, for β¦ of statements, and so on. This page describes loops using the most basic for.
By default, for blocks require three expressions.
- Expressions performed before repeated execution
- Expression for the conditions under which the iteration statement code is executed
- Expression after executing the iteration statement code
You can create a repeat statement using the following three expressions.
for (expression 1; expression 2; expression 3) {
// code block to be executed
}
For example, you can use the following basic iterations.
for (let i = 0; i < 10; i++) {
console.log("Current i: ", i);
}
In this case, assign a variable called i to zero before executing the iteration statement, and increase the value of i by 1 for each code run. Repeat this operation only if i is less than 10.
For more repeat statements, you can refer to the following documents.