fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@ -0,0 +1,50 @@
---
title: Break Statement
localeTitle: 休息声明
---
## 介绍
**break**语句终止当前循环, `switch``label`语句,并将程序控制转移到终止语句后面的语句。
```
break;
```
如果在带标签的语句中使用**break**语句,则语法如下:
```
break labelName;
```
## 例子
以下函数有一个**break**语句,当**i**为3时终止`while`循环,然后返回值**3 \* x** 。
```
function testBreak(x) {
var i = 0;
while (i < 6) {
if (i == 3) {
break;
}
i += 1;
}
return i * x;
}
```
![:rocket:](//forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=2 ":火箭:") [运行代码](https://repl.it/C7VM/0)
在以下示例中计数器设置为从1到99计数;但是, **break**语句在14次计数后终止循环。
```
for (var i = 1; i < 100; i++) {
if (i == 15) {
break;
}
}
```
![:rocket:](//forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=2 ":火箭:") [运行代码](https://repl.it/C7VO/0)
## 其他资源:
[MDN链接](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break) | [MSDN链接](https://msdn.microsoft.com/en-us/library/3fhdxafb.aspx)

View File

@ -0,0 +1,58 @@
---
title: Continue Statement
localeTitle: 继续声明
---
## 介绍
**continue**语句终止当前或标记循环的当前迭代中的语句的执行,并继续执行下一次迭代的循环。
```
continue;
```
如果在带标签的语句中使用**continue**语句,则语法如下:
```
continue labelName;
```
与**break**语句相反, **continue**不会完全终止循环的执行;代替:
*`while`循环中,它会跳回到条件。
*`for`循环中,它跳转到更新表达式。
## 例子
以下示例显示了一个`while`循环,该循环具有一个**continue**语句,该语句在**i的**值为3时执行。因此 **n**取值为1,3,7和12。
```
var i = 0;
var n = 0;
while (i < 5) {
i++;
if (i === 3) {
continue;
}
n += i;
console.log (n);
}
```
![:rocket:](//forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=2 ":火箭:") [运行代码](https://repl.it/C7hx/0)
在下面的示例中循环从1到9迭代。由于将**continue**语句与表达式`(i < 5)`一起使用,因此跳过了**continue**和`for` body结尾之间的语句。
```
for (var i = 1; i < 10; i++) {
if (i < 5) {
continue;
}
console.log (i);
}
```
![:rocket:](//forum.freecodecamp.com/images/emoji/emoji_one/rocket.png?v=2 ":火箭:") [运行代码](https://repl.it/C7hs/0)
## 其他资源
* [MDN链接](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/continue)
* [MSDN链接](https://msdn.microsoft.com/en-us/library/8de3fkc8.aspx)

View File

@ -0,0 +1,38 @@
---
title: Do...While Loop
localeTitle: 做......循环
---
`do...while`循环与[`while`](http://forum.freecodecamp.com/t/javascript-while-loop/14668)循环密切相关。在do while循环中在循环结束时检查条件。
这是`do...while`循环的**语法**
## 句法:
```
do {
*Statement(s);*
} while (*condition*);
```
**statements**在计算条件或布尔表达式之前**至少**执行**一次的**语句,并**在**每次条件计算结果为true时重新执行。
**condition**这里,条件是布尔表达式 。如果布尔表达式的计算结果为true则再次执行该语句。当布尔表达式求值为false时循环结束。
## 例:
```
var i = 0;
do {
i = i + 1;
console.log(i);
} while (i < 5);
Output:
1
2
3
4
5
```
来源: [**做......同时**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/do…while)

View File

@ -0,0 +1,70 @@
---
title: For...In Loop
localeTitle: 对于... In Loop
---
`for...in`语句以任意顺序迭代对象的可枚举属性。对于每个不同的属性,可以执行语句。
```
for (variable in object) {
...
}
```
|必需/可选|参数|说明| | ------------------- | ----------- | ----------------- -------------------------------------------------- --- | |必需|变量|每次迭代都会为变量分配不同的属性名称。 | |可选|对象|迭代其可枚举属性的对象。 |
## 例子
```
// Initialize object.
a = { "a": "Athens", "b": "Belgrade", "c": "Cairo" }
// Iterate over the properties.
var s = ""
for (var key in a) {
s += key + ": " + a[key];
s += "<br />";
}
document.write (s);
// Output:
// a: Athens
// b: Belgrade
// c: Cairo
// Initialize the array.
var arr = new Array("zero", "one", "two");
// Add a few expando properties to the array.
arr["orange"] = "fruit";
arr["carrot"] = "vegetable";
// Iterate over the properties and elements.
var s = "";
for (var key in arr) {
s += key + ": " + arr[key];
s += "<br />";
}
document.write (s);
// Output:
// 0: zero
// 1: one
// 2: two
// orange: fruit
// carrot: vegetable
// Efficient way of getting an object's keys using an expression within the for-in loop's conditions
var myObj = {a: 1, b: 2, c:3}, myKeys = [], i=0;
for (myKeys[i++] in myObj);
document.write(myKeys);
//Output:
// a
// b
// c
```
# 资源:
* [MDN链接](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for…in)
* [MSDN链接](https://msdn.microsoft.com/library/55wb2d34.aspx)

View File

@ -0,0 +1,86 @@
---
title: For Loop
localeTitle: 对于循环
---
### 句法
```javascript
for ([initialization]); [condition]; [final-expression]) {
// statement
}
```
javascript `for`语句由三个表达式和一个语句组成:
## 描述
* 初始化 - 在循环上第一次执行之前运行。此表达式通常用于创建计数器。这里创建的变量的范围是循环。一旦循环完成它的执行就会被破坏。
* condition - 在每次迭代执行之前检查的表达式。如果省略则此表达式的计算结果为true。如果计算结果为true则执行循环语句。如果计算结果为false则循环停止。
* final-expression - 每次迭代后运行的表达式。通常用于增加计数器。但它也可以用来递减计数器。
* statement - 要在循环中重复的代码
这三个表达式中的任何一个或语句都可以省略。 For循环通常用于计算一定数量的迭代以重复语句。在条件表达式求值为false之前使用`break`语句退出循环。
## 常见的陷阱
**超过数组的边界**
当多次索引数组时很容易超出数组的边界例如尝试引用3元素数组的第4个元素
```javascript
// This will cause an error.
// The bounds of the array will be exceeded.
var arr = [ 1, 2, 3 ];
for (var i = 0; i <= arr.length; i++) {
console.log(arr[i]);
}
output:
1
2
3
undefined
```
有两种方法可以修复此代码。将条件设置为`i < arr.length``i <= arr.length - 1`
### 例子
迭代0-8的整数
```javascript
for (var i = 0; i < 9; i++) {
console.log(i);
}
output:
0
1
2
3
4
5
6
7
8
```
在条件表达式为false之前中断循环
```javascript
for (var elephant = 1; elephant < 10; elephant+=2) {
if (elephant === 7) {
break;
}
console.info('elephant is ' + elephant);
}
output:
elephant is 1
elephant is 3
elephant is 5
```
### 其他资源
* [MDN - 用于陈述](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for)

View File

@ -0,0 +1,88 @@
---
title: For...Of Loop
localeTitle: 对于...... Of Loop
---
`for...of`语句创建循环遍历可迭代对象包括ArrayMapSetArguments对象等调用自定义迭代挂钩其中包含要为每个不同属性的值执行的语句。
```javascript
for (variable of object) {
statement
}
```
| |说明| | ---------- | ------------------------------------- | |变量|在每次迭代时,将不同属性的值分配给变量。 | |对象|迭代其可枚举属性的对象。 |
## 例子
### 排列
```javascript
let arr = [ "fred", "tom", "bob" ];
for (let i of arr) {
console.log(i);
}
// Output:
// fred
// tom
// bob
```
### 地图
```javascript
var m = new Map();
m.set(1, "black");
m.set(2, "red");
for (var n of m) {
console.log(n);
}
// Output:
// 1,black
// 2,red
```
### 组
```javascript
var s = new Set();
s.add(1);
s.add("red");
for (var n of s) {
console.log(n);
}
// Output:
// 1
// red
```
### 参数对象
```javascript
// your browser must support for..of loop
// and let-scoped variables in for loops
function displayArgumentsObject() {
for (let n of arguments) {
console.log(n);
}
}
displayArgumentsObject(1, 'red');
// Output:
// 1
// red
```
# 其他资源:
* [MDN链接](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for…of)
* [MSDN链接](https://msdn.microsoft.com/library/dn858238%28v=vs.94%29.aspx?f=255&MSPPError=-2147217396)
* [参数@@ iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/@@iterator)

View File

@ -0,0 +1,15 @@
---
title: Loops
localeTitle: 循环
---
循环在JavaScript中用于根据条件执行重复任务。条件通常在分析时返回`true``false` 。循环将继续运行,直到定义的条件返回`false`
循环有三种常见类型:
* [对于](http://forum.freecodecamp.com/t/javascript-for-loop/14666)
* [](http://forum.freecodecamp.com/t/javascript-while-loop/14668)
* [做的](http://forum.freecodecamp.com/t/javascript-for-loop/14662)
您可以键入`js for` `js while``js do while`以获取有关这些内容的更多信息。
> 链接: [MDN **for循环**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for)

View File

@ -0,0 +1,34 @@
---
title: Labeled Statement
localeTitle: 标签声明
---
## 标签声明
**Labeled语句**与`break``continue`语句一起使用,用于标识`break``continue`语句适用的语句。
### 句法
\`\`\`\`javascript 标签: 声明
```
### Usage
Without the use of a `labeled` statement the `break` statement can only break out of a loop or a `switch` statement. Using a `labeled` statement allows `break` to jump out of any code block.
#### Example
```
JavaScript的 foo{ console.log“This prints; 打破foo; console.log“这将永远不会打印。”; } console.log“因为执行跳转到这里 / \*输出 这打印: 因为执行跳到这里! \* /
```
When used with a `continue` statement the `labeled` statement allows you to skip a loop iteration, the advantage comes from being able to jump out from an inner loop to an outer one when you have nested loop statements. Without the use of a `labeled` statement you could only jump out of the existing loop iteration to the `next iteration of the same loop.`
#### Example
```
JavaScript的 //没有标记语句当j == i时内部循环跳转到下一次迭代 功能测试() { forvar i = 0; i <3; i ++{ console.log(“i =”+ i; forvar j = 0; j <3; j ++{ ifj === i{ 继续; } console.log(“j =”+ j; } } }
/ \*输出 i = 0注意缺少j = 0 J = 1 J = 2 I = 1 j = 0注意缺少j = 1 J = 2 I = 2 J = 0 j = 1注意缺少j = 2 \* /
//使用带标签的语句我们可以跳转到外部i循环 功能测试 { outerforvar i = 0; i <3; i ++{ console.log(“i =”+ i; forvar j = 0; j <3; j ++{ ifj === i{ 继续外 } console.log(“j =”+ j; } } }
/ \* i = 0j仅在小于i时记录 I = 1 J = 0 I = 2 J = 0 J = 1 \* / \`\`\`
### 更多信息:
[MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label)

View File

@ -0,0 +1,45 @@
---
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)_