break continue循环中常用的结束 执行语句

左先生 2020-09-30 PM 218℃ 0条

break : 结束循环
18733-rhz635iu03s.png

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>break</title>
</head>
<body>
    <script type="text/javascript">
        var i=0;
        while(i<100){
            if(i%2==0){
                document.write(i);
                break;
            }
            i++;
        }
    </script>
</body>
</html>

continue : 结束循环并且返回上一个循环

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>continue</title>
</head>
<body>
    <script type="text/javascript">
        var i=0;
        while(i<100){
            i++;
            if(i%2==0){
                continue;
            }
            console.log(i);
        }
    </script>
</body>
</html>

40513-fdv6vknoxim.png

标签: while, break, continue

非特殊说明,本博所有文章均为博主原创。

评论啦~