Home > Web Front-end > JS Tutorial > JS for while loop

JS for while loop

php中世界最好的语言
Release: 2018-03-20 10:01:42
Original
2142 people have browsed it

This time I will bring you the for while loop of JS, what are the precautions for using the for while loop of JS, the following is a practical case, let's take a look.

Loop statement:

For

## for loop format

for(var i = 0; i < 10;  i ++){   }
Copy after login

For loop execution sequence:

Enter ② Judgment... Loop

If the judgment is false, end

while

 

while loopFormat

var i = 0;
while(i < 10){ 
    alert();
    i ++;    break;
}
Copy after login
If i<10 is replaced with true, the while loop will continue to execute. until the conditional control ends.

break ends all loops

continue skips this loop and will execute the following.

for(){
     If(i ==2){
        Continue;
    }                            
}
Copy after login
View Code

will skip the case of i=2, end i=1 and then execute i=3.

The difference between for and while

To determine the number of times, use for

While while terminates the loop until a certain condition is met. (Looking for books in the library, I don’t know how many books)

Variable classification:

1. Global variables are also called external variables, which are variables defined outside the function. It does not belong to a function, it belongs to a source program file. Its scope is the entire source program.

2. Local variables In a program, variables that can only be accessed in a specific procedure or function are relative to global variables

Scope:

The scope of the variable Only within defined curly braces.

Short circuit:

Only performs one operation, high efficiency

Other content:

 

Typeof

DetermineData type There is a return value                                           # (Can you assign a value to a variable?) Var num = 1+2 && 3+4 Output 3 is judged to be true because both sides are true

 0 false Not 0 true

Empty false

Non-empty true

##Notes

Homework questions:

Control statementNote the format

if(判断){
    alert();
}else{
    alert();
}
Copy after login

if语句格式

    变量要在开头定义。

    重复的代码要优化重构。

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

max-width和min-width的使用技巧

android textinput显示不全怎么解决

The above is the detailed content of JS for while loop. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template