The for loop iterates over a range of values using an index variable. It consists of three parts: initialization, condition, and iteration.
The while loop repeats a block of code as long as a specified condition remains true.
The do...while loop is similar to the while loop, but it ensures that the loop block is executed at least once before checking the condition.
Loop Control Statements
- break: Exits the loop prematurely.
- continue: Skips the rest of the current iteration and proceeds to the next.
Looping Through Arrays
Loops are commonly used to iterate through arrays:
For...of Loop (ES6)
The for...of loop simplifies iterating through arrays and other iterable objects.