Suppose I want to compute square roots a lot of places in a big chunk of code.
假设我想在一大段代码中,计算很多次平方根。
This chunk of code and this chunk of code, they're really doing the same thing.
这一块代码和这一块代码,它们实际上是相同的功能。
You're not alone if you've ever come across a chunk of code with a comment like this one.
如果您曾经遇到过带有此类注释的代码,这种情况并不少见。
You've got to do it above this chunk of code, you've got to do it inside this chunk of code.
你不得不在一大段代码之上来实现它,你不得不在一大段代码之内来实现它。
This chunk of code and this chunk of code, they're really doing the same thing.
这一块代码和这一块代码,它们实际上是相同的功能。
So conceptually the key difference here, besides the syntax looking slightly different, it just means that if you want a chunk of code to execute no matter what initially, ; you can use the do while loop; if you want to check a condition first, you can use the while loop.
所以概念上,则关键的区别是,除了语法看起来有点不同,它的意思是如果你想要一段代码,最初无论如何都要执行,你就可以用do,while循环;,如果你想要先检查条件,你可以用while循环。
应用推荐