Home > Article > Web Front-end > JS for while loop
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 ++){ }
For loop execution sequence:
Enter ② Judgment... Loop If the judgment is false, endwhile
while loopFormat
var i = 0; while(i < 10){ alert(); i ++; break; }If i<10 is replaced with true, the while loop will continue to execute. until the conditional control ends. break ends all loopscontinue skips this loop and will execute the following.
for(){ If(i ==2){ Continue; } }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(); }
if语句格式
变量要在开头定义。
重复的代码要优化重构。
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
The above is the detailed content of JS for while loop. For more information, please follow other related articles on the PHP Chinese website!