原稿
C++中有三种可用的循环结构 there are three looping structures avaliable in C++
你能用它们多次执行一个代码块 All the way you use to execute the code block multiple times.
while循环在条件为真的时候才会执行代码块 the while loop runs through the code block only if the condition is true.
只要条件继续保持为真循环就继续执行。 and will continue looping for as long as the condition remains true
每次循环开始的时候会检查条件。 bear in mind that the condition is only checked the start of each iteration.
do while循环与while循环很像 do while loop works in the same way as the while loop
只是它是在代码执行后检查条件 except that it check the condition after the code block.
所以它至少会执行一次代码块 it will therefore always run through the code block at least once.
留意代码是用分号结束的。 noticed that the loop ends with a semicolon.
for循环是将一段代码执行特定的次数 the for loop is used to run through a code block a specific number of times.
它用到三个参数 it uses three parameters.
第一个初始化计数器大小 the first one initialize size counter.
它会在循环之前执行一次 and it always executed once before the loop
第二个参数包含了循环的条件 the second parameter holds the condition for the loop
会在每次循环之前检查一次 and it check before each iteration.
第三个参数包含了对计数器的执行 the third parameter contains the implement of the counter.
它会在每次循环的末尾执行 and it's executed at the end of each iteration.
for循环有一种变体 the for loop has several variations.
对于初学者来说, 第一个与第三个参数可以分解为几个语句 for starters, the first and third parameters can be split into several statements.
方法就是使用comma符号 by using the comma operator
还有一个方法是不设置任何参数, 让循环无限进行下去 there is also the option of leaving out anyone of the parameters making the loop go on for ever.
对于条件语句if来说 just with the conditional if statement
代码块中如果只有一条语句, 那么就可以去掉括号。 the curly brackets for the loops can be left out if there is only one statement in the code block.
有两个跳转语句让循环继续下去 there are two jump statements can be used inside the loops for it to continue.
break关键字会让循环结构终止。 the break key will ends the loop structure.
continue就跳过当前循环的余下部分, 而从下一个循环的开始部分执行。 and continue escapes the rest of current iteration and continues at the beginning of the next iteration.
第三个或许有用的跳转语句就是goto the third jump statement mybe useful to know is goto
它可以跳转到特定的标签上 which performs an conditional jump to a specified label.
这个结构几乎没有用到过, 因为它会让程序代码难以跟踪 this instruction is generally never used since it tends to make the flow execution difficult to follow
校正后
C++中有三种循环结构 there are three looping structures avaliable in C++
它们都可以让你循环多次执行一段代码 All of which you use to execute the code block multiple times.
只有当条件为真的时候while循环才会执行代码块 the while loop runs through the code block only if the condition is true.
并且只要条件继续保持为真,那么循环就继续执行。 and will continue looping for as long as the condition remains true
记住只是在每次循环开始的时候检查条件。 bear in mind that the condition is only checked at the start of each iteration.
do while循环与while循环的工作方式很类似 the do while loop works in the same way as the while loop
不过它是在代码块之后检查条件 except that it check the condition after the code block.
因此它至少会执行一次代码块 it will therefore always run through the code block at least once.
注意代码是用分号结束的。 noticed that the loop ends with a semicolon.
for循环是用于将一段代码执行特定的次数 the for loop is used to run through a code block a specific number of times.
它用到三个参数 it uses three parameters.
第一个初始化计数器 the first one initializes the counter.
它总是会在循环之前执行一次 and it always executed once before the loop
第二个参数包含了循环的条件 the second parameter holds the condition for the loop
它会在每次循环之前检查一次 and it's checked before each iteration.
第三个参数包含了计数器的增量信息 the third parameter contains the increment of the counter.
它会在每次循环的末尾执行 and it's executed at the end of each iteration.
for循环有一种变体 the for loop has several variations.
对于初学者来说, 第一个与第三个参数可以分解为几个语句 for starters, the first and third parameters can be split into several statements.
方法就是使用comma符号 by using the comma operator
还有一个方法是不设置任何参数, 让循环无限进行下去 there is also the option of leaving out anyone of the parameters making the loop go on for ever.
对于条件语句if来说 just with the conditional if statement
如果代码块中只有一条语句, 那么可以去掉花括号。 the curly brackets for the loops can be left out if there is only one statement in the code block.
有两个跳转语句让循环继续下去 there are two jump statements can be used inside the loops for it to continue.
break关键字会让循环结构终止。 the break keyword will ends the loop structure.
continue就跳过当前循环的余下部分, 而从下一个循环的开始部分执行。 and continue escapes the rest of current iteration and continues at the beginning of the next iteration.
第三个或许有用的跳转语句就是goto the third jump statement mybe useful to know is goto
它可以无条件跳转到特定的标签上 which performs unconditional jump to a specified label.
这个结构基本没有用到过, 因为它会让程序代码变得难以理解 this instruction is generally never used since it tends to make the flow execution difficult to follow
|