Get the App
SLTechnology News&Howtos  ›  Development  › 

Which type of loop does javascript while belong to?

Shulou Source: shulou.com Published: 2022-06-03 02:31:01 09月16日 Update

This article mainly explains "which type of cycle javascript while belongs to". Friends who are interested may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn which type of cycle javascript while belongs to.

In javascript, while is a kind of equivalent loop statement, which needs to judge the loop condition first, then execute the loop body when the condition is satisfied, and jump out of the loop if it is not satisfied. The characteristic of while statement: judge the expression first, and execute the corresponding statement when the result of the expression is true.

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

While loop statement is a kind of equivalent loop statement, which first judges the loop condition, executes the loop body when the condition is met, and stops when it is not satisfied.

Function: to perform an operation repeatedly until the specified condition is not established.

Features: first judge the expression, and execute the corresponding statement when the result of the expression is true.

The general form of a while loop is:

While (expression) {/ / expression is a circular conditional statement block; / / code block to be executed}

Statement parsing:

First evaluate the value of the "expression". When the value is true, execute the "statement block" in the loop.

Note: the evaluation result of the "expression" is of Boolean type (TRUE or FALSE). If it is a value of other types, it will be automatically converted to a value of Boolean type (because PHP is a weak language type, it will automatically convert the variable to the correct data type according to the value of the variable).

A statement block is a collection of one or more statements surrounded by {}; if there is only one statement in the statement block, {} can also be omitted.

After execution, return to the expression, evaluate the value of the expression again to judge, when the value of the expression is true, then continue to execute the "statement block". This process will be repeated all the time.

Do not jump out of the loop until the value of the expression is false and execute the statement below while.

The execution flow of the while loop is shown in the following figure:

Example: use a while loop to calculate the sum of all integers between 1 and 100:

Var iTunes 1 var sum=0;while (I

Tags: Loops statements expressions types conditions results Boolean loop body content variables characteristics learning utility deeper between code action interest again only Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft Xiaomi vpn Shulou Tech Info