JavaScript-流程控制

if判断

        var age = 3;
        if(age>3){
            alert("haha");
        } else {
            alert("wawa");
        }


while循环避免程序死循环

        while(age<100){
            age = age +1;
            console.log(age);
        }


for循环

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


for...in

        //console.log(score) 在浏览器的控制台打印变量!
        var age = [3,6,9];
        //for(var index in object){}
        for(var num in age){
            if(age.hasOwnProperty(num)){
                console.log("存在")
                console.log(age[num])
            }
        }


forEach循环

        var age = [3,6,9];
        age.forEach(function (value){
            console.log(value)
        })

posted on 2022-05-09 13:14  言语说  阅读(16)  评论(0编辑  收藏  举报

导航