Home > Web Front-end > JS Tutorial > Javascript Basic Tutorial: While Statement_Basic Knowledge

Javascript Basic Tutorial: While Statement_Basic Knowledge

WBOY
Release: 2016-05-16 16:19:32
Original
1344 people have browsed it

The function of a loop statement is to repeatedly execute the same piece of code. Although it is divided into several different types, the principle is almost the same; as long as the given conditions are met, the statements contained in the loop body will continue to execute. Once the conditions are no longer Terminate when satisfied.

The while loop is a pre-test loop, which means that the conditional judgment of whether to terminate is before the code is executed. Therefore, the body of the loop may not be executed at all. Its syntax is as follows:

while(expression) statement

When expression is true, the program will continue to execute statement statements until expression is false.

Two cases

Copy code The code is as follows:


Click the button below to loop the code block as long as i is less than 5.




<script><br> Function myFunction()<br> {<br>         var x="",i=0;<br>             while (i<=10)<br />             {<br />                   x=x "The number is " i "<br>";<br>               i ;<br>          }<br>            document.getElementById("demo").innerHTML=x;<br> }<br> </script>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template