簡體   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>

所以......正如你在這里看到的,每當我在我的瀏覽器(firefox,chrome)上重新加載它時,它只會繼續重新加載並且不會打開,但是當我使用 for 循環然后使用 if 條件跳過循環時, 它打開。 請問我做錯了什么,因為我剛開始學習javascript。

這是因為您正在創建一個無限循環。 當你有if語句和continue關鍵字時,它將跳到下一個循環而不增加w變量。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM