Home > Blockchain >  When i execute an if condition with the continue keyword in a while loop my browser dosen't ope
When i execute an if condition with the continue keyword in a while loop my browser dosen't ope

Time:07-11

<!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. Please is there something i'm doing wrong, Because i just started learning javascript.

CodePudding user response:

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.

  • Related