码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript语法详解(三)

时间:2016-06-23 01:13:21      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:javascript语法详解(三)

一、JavaScript循环语句

    1.for循环、for/in

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        var array = [1,2,3,4,5,6];
        for(var i=0; i<6; i++){
            document.write(array[i]+" ");
        }
    </script>

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        var array = [1,2,3,4,5,6];
        var i;
        for(i in array){
            document.write(array[i]+"<br/>");
        }
    </script>

</body>
</html>

    

    2.while循环、do...while

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        var i = 1;
        while(i<10){
            document.write("i="+i+"<br/>")
            i++;
        }
    </script>

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <script>
        var i = 10;
        do {
            document.write("i="+i+"<br/>")
            i++;
        }while(i<10)
    </script>

</body>
</html>

    

JavaScript语法详解(三)

标签:javascript语法详解(三)

原文地址:http://11317783.blog.51cto.com/11307783/1791896

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!