You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`if` statement is a condition statement, it can used to determine a condition is true or false. If true, then the code in the `if` statement block will be execute. The grammar of `if` is:
`if` statement can be used together with `else` statement, `else` statement used to execute the code when the condition in `if`is false. The grammar of `if-else` is shown:
`condition` is a boolean expression, it’s value is `true` or `false`. If the value of `condition` is `true`, then `#code1‘ will be execute; Else, ’#code2‘ will be execute.
`condition` is an boolean expression, when `condition` is `true`, it’ll execute the code block in `#code`. Then, determine the value of `condition` again. If value of `condition` is `true`, then `#code` will be execute; loop again and again, until the value of `condition` is `false`.
`do-while` statement is similar with `while` statement, but no matter the condition is true or false, it’ll execute the statement in the loop once, and then determine the condition to see continue execution or not. The grammar of `do-while` is shown below:
60
60
61
61
```mcfpp
62
62
do{
63
63
#code
64
64
}while (condition);
65
65
```
66
66
67
-
## for语句
67
+
## for statement
68
68
69
-
`for`语句是循环的一种稍复杂的版本,它的语法如下:
69
+
`for` statement is a more complex version of loop, it’s grammar is:
`forinit` is an initialization expression, used to initialize loop variable. `condition` is a boolean expression, used to determine if the loop keeps going on. `forupdate` is a update expression, used to update the variable of the loop. `#code` represents the loop body, which is the code in the loop. The execute process of `for` is shown below:
1.Execute `forinit`, initialize the loop variable.
80
+
2.Determine the value of `condition`, if the value of `condition` is `true`, execute `#code`, then execute `forupdate`, to update the loop variable, and determine the value of `condition` again.
81
+
3.If the value of `condition` is `false`, exit the loop.
82
82
83
-
`for`循环中,`forinit`声明的变量只在`for`循环中有效。
83
+
In `for` loop, the declaration of variable `forinit` only valid in the `for` loop.
84
84
85
-
## break和continue语句
85
+
## break and continue statement
86
86
87
-
`break`语句用来跳出整个循环,`continue`语句用来跳过本次循环。例如:
87
+
`break` statement used to jump out the whole loop, `continue` statement used to skip the current loop. For example:
In this example, when the value of `i` is `5`, `break`will jump out of the loop; when the value of `i` is `3`, `continue` will jump this loop, go to the next loop directly. So, the change of I in each loop are:`0`,`1`,`2`,`4`,`5`, and finally jump out.
102
102
103
-
`break`和`continue`语句只能在循环中使用。
103
+
`break` and `continue` statement only can be used in the loop
0 commit comments