Home of web learners

www.webn3rd.com

loop is used to execute a script within a condition

Lets start with an example:

<html>
<head>
    
</head>
<body>
    <script>
    var i;
    for(i=1;i<10;i++){
        document.write(i);
    }
</script>       
</body>
</html>

output:

123456789

Here,we use for loop to do the same work again and again,so in i=1 we initialize counting variable

After semicolon we check the condition to limit the loop to how much number of time we want to execute our for loop body,which start from { and end with }

Then after semicolon this part is for increment or decrement counter variable,here we increment by 1

And in the body part,we execute the data in i to see is for loop working,we see that it shows that i is increasing,end with the condition

webn3rd.com

About webn3rd