Home >Web Front-end >Front-end Q&A >What is the meaning of while in javascript

What is the meaning of while in javascript

WBOY
WBOYOriginal
2021-12-07 14:00:022264browse

In JavaScript, while means "when...the condition is met". It is a loop statement with the syntax of "while (condition) {code block to be executed}"; when the specified condition is true , the while loop will continue to execute the code block in "{}".

What is the meaning of while in javascript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What does while mean in JavaScript

In JavaScript, the meaning of while is "when...", "when... is satisfied. ..conditions”. Is a loop statement, the while loop will continue to loop through the code block as long as the specified condition is true.

The syntax is as follows:

while (条件) {要执行的代码块}

The example is as follows:

<html>
<body>
<h2>JavaScript while</h2>
<p id="demo"></p>
<script>
var text = "";
var i = 0;
while (i < 10) {
  text += "<br>数字是 " + i;
  i++;
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>

Output result:

What is the meaning of while in javascript

[Recommended learning :javascript advanced tutorial

The above is the detailed content of What is the meaning of while in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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