freeCodeCamp/guide/chinese/javascript/loops/while-loop/index.md

45 lines
913 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: While Loop
localeTitle: 而Loop
---
while循环首先评估条件。如果条件为真则执行语句。如果条件为假则不执行语句。之后while循环结束。
这是while循环的**语法**
## 句法:
```
while (condition)
{
statement(s);
}
```
_statements_只要条件求值为true就执行的语句。
_condition_这里condition是一个布尔表达式在每次循环之前计算。如果此条件的计算结果为true则执行语句。当condition的计算结果为false时继续执行while循环后的语句。
## 例:
```
var i = 1;
while (i < 10)
{
console.log(i);
i++; // i=i+1 same thing
}
Output:
1
2
3
4
5
6
7
8
9
```
_来源 [While Loop - MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while)_