JavaScript——流程控制

if判断

1 var age=3;
2     if(age>3){      //第一个判断
3     alert("haha");
4     }else if(age<5){    //第二个判断
5     alert("hehe");
6     }else{         //否则
7     alert("kuwa~");
8     }

while循环

1 var age=3;
2     while(age<100){
3        age=age+1;
4        console.log(age)
5        }

 

for循环

1 for(let i=0;i<=100;i++){
2         console.log(i);
3         }

 

do...while循环

1 var age=3;
2     do{
3         age+=1;
4         console.log(age);
5         }while(age<100)

 

forEach循环

> 5.1版本引入

1 var age=[12,123,43,53,23];
2 
3     //函数
4     age.forEach(function (value) {
5         console.log(value);
6         })

 

for...in循环

1 //for(var index in object){}
2     for(var num in age){
3        if (age.hasOwnProperty(num)){
4           console.log("存在");
5           console.log(age[num]);
6           }
7        }

 

 

 

 

 

 

posted @ 2021-05-04 22:02  cengxuyuan  阅读(57)  评论(0)    收藏  举报