DEV Community

vishwa v
vishwa v

Posted on

While Loop

The while loop loops through a block of code as long as a specified condition is true.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let i=1
        while(i<=5)
    {
        console.log("hi")
        i++;
    }

    let j=1
    while(j<=5){
        console.log(j)
        j++;
    }

    let k=1
    while(k<=10){
        console.log(k)
        k+=2;
    }

    let q=1
    while(q<=15){
        if(q%3==0){
            console.log(q)
        }
        q++;
    }



    let m=1
    while(m<=50){
        if(m%3==0 && m%5==0){
            console.log(m)
        }
        m++;
    }

    let l=1
    while(l<=50){
        if(l%3==0 || l%5==0){
            console.log(l)
        }
        l++;
    }

    </script>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)