10 for循环介绍和应用

<!DOCTYPE html>
<html>
<head>
    <title>for循环</title>
</head>
<body>
    <script type="text/javascript">
        // for(初始化条件;结束条件;递增条件){
        //  run this code
        // }
        
        var i;
        for(i = 1;i <= 10000;i++){
            console.log(i);
            sum = sum + i;
        }
        console.log(sum);  

        var shopping = ['香蕉','苹果','牛奶'];
        
        var j;
        for(j = 0;j < shopping.length;j++){
            // console.log(shopping[j]);
            // document.write(shopping[j]);
            // html标签和javascript组合
            var htmlStr = '<h1>'+shopping[j]+'</h1>';
            console.log(htmlStr);
            document.write(htmlStr);
        }

    </script>
</body>
</html>
原文地址:https://www.cnblogs.com/wuhui1222/p/14168037.html