简体   繁体   English

当我在 while 循环中使用 continue 关键字执行 if 条件时,我的浏览器无法打开

[英]When i execute an if condition with the continue keyword in a while loop my browser dosen't open

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <head>LOOPS</head>
    <h1 id="string"></h1>
    <script language="javascript" type="text/javascript">
        let w = 10;
        while(w<=15){
            console.log(w)
            if(w==13){
                continue;
            }
            w++
        };
        
    </script>
</body>
</html>

So...As you can see here, Whenever i live reload this on my browser(firefox, chrome) It just keeps on reloading and dosen't open but when i use the for loop and then use the if condition to skip a loop, It opens.所以......正如你在这里看到的,每当我在我的浏览器(firefox,chrome)上重新加载它时,它只会继续重新加载并且不会打开,但是当我使用 for 循环然后使用 if 条件跳过循环时, 它打开。 Please is there something i'm doing wrong, Because i just started learning javascript.请问我做错了什么,因为我刚开始学习javascript。

It's because you're creating an infinite loop.这是因为您正在创建一个无限循环。 When you have the if statement and the continue keyword, it will skip to the next loop without incrementing w variable.当你有if语句和continue关键字时,它将跳到下一个循环而不增加w变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM