Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the loop structures in javascript

Shulou Source: shulou.com Published: 2022-06-02 17:52:50 10月06日 Update

This article will explain in detail what is the loop structure in javascript, and the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

There are three kinds of js loop structures: 1, for loop, syntax "for (initialization statement; loop condition; self-increment or self-subtraction) {code block}"; 2, while loop, syntax "while (conditional statement) {code block}"; 3, "do while" loop, syntax "do {statement block} while;"

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

The so-called loop is the repeated execution of a piece of code, the judgment of the computer is far worse than that of people, and the computer is better at one thing-repeating over and over again. And we call this a loop in JavaScript. Let's take a look at the loops in JavaScript.

What are the structures of js loops

There are three kinds of js loop structures.

For loop = = > is used to traverse the code block multiple times

While loop = = > Loop code block when the specified condition is true

Do while loop = = > Loop code block when the specified condition is true

1. For cycle

For is composed of two parts, the conditional control and the cyclic body.

Syntax:

For (initialization statement; loop condition; self-increment or self-subtraction) {code blocks that need to be repeated;}

The structure of the for statement is as follows:

The execution order of the for loop

1. Initialization expression

2. Cyclic conditional expression

3. Code blocks that need to repeat

4. The operation expression after the loop

A simple for loop that changes the value of a variable at a time

Example: output values from 1 to 100

For (var iTunes 1; I

Tags: Loops conditions code statements structures grammars expressions loop bodies parentheses variables order differences content that is articles more cases knowledge articles computers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia OPPO Reno MySQL Shulou Tech Info vpn