SOURCE

console 命令行工具 X clear

                    
>
console
//for循环
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    function sum_all() {
        var result = 0;
        for (var i = 0; i <= 100; i++) {
            result += i;
        }
        return result
    }

    var s = sum_all();

    alert(s);
</script>
</body>
</html>

-----------------------------------------------------------------------------------------
//while循环
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    function sum_all2() {
        var result2 = 0;
        var i = 0;
        while (i <= 100) {
            i++;
            result2 += i;
        }
        return result2
    }

    alert(sum_all2());
    </script>
</body>
</html>

-----------------------------------------------------------------------------------------
//do-while语句
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    function sum_all3() {
        var result3 = 0;
        var i = 0;
        do {
            i++;
            result3 += i;
        }
        while (i <= 100);

        return result3
    }

    alert(sum_all3())
     </script>
</body>
</html>