Skip to content
the poor coder

for of loop ecmascript 6

Poor Man
Published
Reading time
1 min read

The for loop is a fundamental looping structure available in a wide range of programming languages, including ECMAScript 6. The for loop enables you to iterate over a set of values, running a block of code a certain number of times.    The structure of the for loop is as follows:

Text
for ([initialExpression]; [condition]; [incrementExpression]) {
    // code block to be executed
}

In the "initialExpression" section, you can declare and initialize variables for use within the loop. The "condition" section is where the loop's logic is defined - the loop continues to run until the condition evaluates to false. The "incrementExpression" section is where you can increase or decrease the value of your loop variables, allowing for more complex looping behaviors.    The code block within the for loop can contain any JavaScript statements, such as assignment statements, arrays, objects, or conditionals. The loop will execute the code block once per iteration, and then move on to the next iteration.    Here is an example of a for loop that prints out the numbers 1 to 10:

Text
for (let i = 1; i <= 10; i++) {
    console.log(i);
}

In this example, the loop variable i is declared and initialized to 1 in the initialExpression section. The condition section checks to see if i is less than or equal to 10, and if it is, the code block will be executed. After the code block is executed, the incrementExpression section is run, and i is incremented by 1. This process is repeated until i is greater than 10, at which point the loop is terminated.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC