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; }
for(){ If(i ==2){ Continue; } }
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!