Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära The `for` Loop | Discovering Loops
Introduction to JavaScript
course content

Kursinnehåll

Introduction to JavaScript

Introduction to JavaScript

1. Getting Started
3. Conditional Statements
4. Mastering Functions
5. Exploring Arrays
6. Discovering Loops

book
The `for` Loop

One of the most popular loops, which is available in almost every programming language, is known as the for loop. The for loop is primarily used for executing a block of code a specific number of times.

The general syntax of the for loop is as follows:

js

The initialization part is where we declare & initialize a variable, this part is executed only once - at the start of the loop. The boolean expression in place of the condition defines the loop condition - the loop executes as long as that condition is true. The operation can be any expression which is evaluated or executed after every successful iteration.

The flow of a for loop can be better understood through a flowchart:

Following is an example of a simple for loop which executes a block of code 15 times:

123
for(let i = 0; i < 15; i++) { console.log("This is the " + i + "th iteration"); }
copy

1. What is the primary purpose of a for loop?

2. In the for loop syntax, which part is executed only once?

3. What will be the output of the following code?

question mark

What is the primary purpose of a for loop?

Select the correct answer

question mark

In the for loop syntax, which part is executed only once?

Select the correct answer

question mark

What will be the output of the following code?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 6. Kapitel 1

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

course content

Kursinnehåll

Introduction to JavaScript

Introduction to JavaScript

1. Getting Started
3. Conditional Statements
4. Mastering Functions
5. Exploring Arrays
6. Discovering Loops

book
The `for` Loop

One of the most popular loops, which is available in almost every programming language, is known as the for loop. The for loop is primarily used for executing a block of code a specific number of times.

The general syntax of the for loop is as follows:

js

The initialization part is where we declare & initialize a variable, this part is executed only once - at the start of the loop. The boolean expression in place of the condition defines the loop condition - the loop executes as long as that condition is true. The operation can be any expression which is evaluated or executed after every successful iteration.

The flow of a for loop can be better understood through a flowchart:

Following is an example of a simple for loop which executes a block of code 15 times:

123
for(let i = 0; i < 15; i++) { console.log("This is the " + i + "th iteration"); }
copy

1. What is the primary purpose of a for loop?

2. In the for loop syntax, which part is executed only once?

3. What will be the output of the following code?

question mark

What is the primary purpose of a for loop?

Select the correct answer

question mark

In the for loop syntax, which part is executed only once?

Select the correct answer

question mark

What will be the output of the following code?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 6. Kapitel 1
Vi beklagar att något gick fel. Vad hände?
some-alt