Suppose I want to do little piece of code that's going to do planar geometry, points in the plane.
好,因此我需要一些,把这些东西收集到,一起的一些方式。
So I'm going to comment those out, and let's go down to this piece of code, and uncomment it.
那么我会把这些注释上,让我们看看这段代码,取消注释。
And notice because I have just one line of code inside of each of these branches, what have I clearly omitted?
请注意因为我在每个分支中只有一行代码,显然地我省略了什么?
Right now, I have to take that piece of code and replicate it everywhere I want in my larger file.
现在我要把这段代码,复制到,大文件中的各个部分。
What happens now after we've executed this third line of code, what happens next in the story?
我执行完第三行代码会发生什么呢,在这之后会发生什么呢?
All right, those pieces of code inherently involved something that does depend on the size of the input, or on the particular input.
好,这些代码,肯定会涉及到一些,与输入的大小相关的东西,或者说与特定输入相关。
All right, you can see that this little piece of code, it's got a loop in there, and what's it doing?
好,你们看到的这一小块代码,是做了一个循环吧?,他在做什么?
And they're awfully simple because, all I can do now, is decide whether to execute some piece of code or another.
它们之所以太简单的原因是:,现在我能做的,就是,决定执行一块代码或者执行另外一块。
But there's a key line of code that I lost over a moment ago and that was this one here.
但是我刚才漏了一行关键的代码,就是这里的这一行。
What is that? It's the piece of code we wrote for computing square roots, square roots of actually perfect squares.
对吧?这是什么呢?,这是我们写的计算平方根的代码,计算完全全平方根的。
All right. The fourth thing I'm going to do, is I'm going to then construct the block of code.
好,我要做的第四件事情就是,我会去写这块循环代码。
But if I did have two lines of code or more, I would in fact need to put those back.
但是如果我的确有两行或更多的代码,我其实应该把花括号加上。
You've got to do it above this chunk of code, you've got to do it inside this chunk of code.
你不得不在一大段代码之上来实现它,你不得不在一大段代码之内来实现它。
In fact, this example would compile because you can use curly braces in this way to encapsulate lines of code, but realize for now, that, not good.
实际上,这个例子可以编译,因为你可以用这种方式来压缩代码行,但是请认识到,那个,不太好。
It ultimately evaluates that line of code but just once the stuff inside the curly braces, but the semicolon on the end, essentially has the effect of this.
它最终执行了那行代码,但是只有一次,当那个东西在花括号里,分号放在后面,本质上影响了这个循环。
Well I ought to be able to do that by simply generalizing the loop. And that's what the next piece of code on your a hand out shows you.
好的通过生成这个循环,我应该能够达到目的,这也是你们的讲义中下一段代码。
应用推荐