A brief introduction to JavaScript Loop
JavaScript’s Loop has a wide range of applications. For example, webpage date menus, information catalogue lists, or interactive forms options, many can be handled by JavaScript’s loops, which is equivalent to solving things that simply cannot be done by HTML. In the world, there are two big loops that cannot be ignored, namely the for loop and the while loop . The usage is quite similar to the PHP loop. The difference is that PHP is processed on the server side, while JavaScript is directly on the user side ( Client) processing.
Simple JavaScript loop example
var i=0;
while( i<10 ) {
document.write(i);
i++;
}
</script>
This example uses the while loop, which displays a number from 0 to 9 on the web page. The same result can also be achieved using the for loop. The feature of JavaScript is that you can write such a loop as a function. When you need to use it (for example, netizens select certain options), call it out and display it.
Post a Comment
0 Comments