Downtown Chicago, the city's business center, is known as the Loop.
VOA: special.2009.01.12
We start with j pointing here, and we can see what this loop's going to do, right? j is just going to move up.
我们让j指向这里,我们能看到这个,循环要做什么?,对吧,j要开始移动了。
All right, you can see that this little piece of code, it's got a loop in there, and what's it doing?
好,你们看到的这一小块代码,是做了一个循环吧?,他在做什么?
Now, all the cat is doing is that it's an infinite loop and it's checking if I am not facing bird, - face bird, and it's -- It's constantly chasing the bird.
猫能做的就是一个死循环,并且它能检测我是不是面对着一只鸟,如果没有就转向那只鸟-,它一直不停地追逐这只鸟。
We'll loop back as we go through the class to questions about what's gone so horribly wrong, and more important, from a public health point of view, what can be done about it?
当所有的课都上完后我们会再回头看,到底是什么出了问题,更重要的是,从公共健康的角度来看,如何才能纠正这些错误呢
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.
好的通过生成这个循环,我应该能够达到目的,这也是你们的讲义中下一段代码。
So this is a nice little search-- sorry, a nice little sort algorithm . And in fact, it's relying on something that we're going to come back to, called the loop invariant.
恩,这是一个很棒的小搜索,抱歉,和很棒的小排序算法,事实上,它依赖于一些我们要回顾的东西,被称作循环不变量。
Well, let's take a look at this high7 variant that also use loops that also uses a loop. So this one is a little cute, I like to think. So notice this.
让我们看下这个仍然使用了循环的版本,这个有点意思,我认为,注意这个。
If we weren't so pressed for time, I kinda wanna see how long we could get away with this before it gets awkward, but that, in fact, is an infinite loop t hat's hopefully deliberate.
如果有时间,我想看看,我们需要花多长时间解决这一问题,事实上,它是我故意,使用的无穷循环。
And what's this little loop say to do? This little loop says I'm going to write a function or procedures that takes in two messages.
这个小循环是做什么的,这个小的循环是,我要写一个函数或者过程来接受两条消息。
So in a sense, that's a good infinite loop that is as long as you're using the program, it's constantly checking your grammar and spelling, and underlining things, so infinite loops aren't necessarily bad if the objective is actually being met.
因此从这个意义上说,这是个好的无穷循环,只要你开始使用这个软件,它不停的检查你的语法,拼写或者下划线等,通过这种方式达到目标的时候,这样的无穷循环并不总是坏的。
If you look at solve 2, it's going to solve2 run through the same kind of loop, printing out all of the answers.
我会让你们看一看,如果你在看,那将运行相同的循环。
Which means, next time through the loop, that's going to pop out and return an answer.
循环会跳出并返回这个答案,如果不相等的话。
You've got a loop, you've got a condition and a boolean to check if he's touching the edge, and some statements to tell him to shout or to actually turn around.
我们有一个循环,通过一个条件和一个布尔值来判断,是否触到了边缘,还有一些语句,让它回头并咆哮。
If you're not updating some variable by incrementing it or decrementing it -- if you're not changing anything, presumably the conditions are never going to evaluate to false or the opposite, so you're just going to have an infinite loop, which might be your goal, but odds are it's not.
如果你不通过增加或减少它来改变一些变量,-如果你不改变什么,大概那个条件永远不会变成错误的,或相反的,所以你将得到一个无限循环,那可能是你的目标,但可能也不是。
Oh, there's a man at the store and now we have a loop where he is just looking through my inventory one at a time and reciting what it is I actually picked up.
商店里有一个人,现在我们有一个循环,通过这个循环他可以看到我的库存,然后显示出来我实际上都采摘了哪些水果。
So it's initialized outside the loop when it should be initialized inside the loop. Or conversely, inside the loop when it should be outside the loop. So look carefully at when variables are being initialized.
却忘记了,意思就是它本来应该,是在循环外初始化,但是却是在循环初始化的,所以在初始化变量的时候注意这一点。
swap I'm going to keep track of a little variable called swap, it's initially true, and as long as it's true, I'm going to keep going, but inside of the loop I'm going to set it to false, and only if I do a swap will I set it to true.
我打算跟踪一个小的变量称为,初始值为真,只要它是真的,算法就会继续,但是在循环里,我打算把他设为假,除非交换发生,就把它设为真。
They're running through a loop. It's a common way of thinking about problems.
有继承意义的迭代程序了,它们是以循环的模式来运行的。
It's basically cycling through the loop a multiplying by a each time.
这个代码就是简单的循环,每次乘一个。
And that's very nice, because this allows me to be sure that my FOR loop is going to terminate.
因为这让我确信我的FOR循环是会终止的,因为只要集合是有限的。
What's the first thing I do in a loop?
我在循环中做的第一件事情是什么呢?
And so what's the loop going to do?
字符的序列来对待了?
What's the complexity of that inner loop?
我只想要得到内嵌的这个循环的复杂度?
Now there's this last type of loop.
现在这里还有最后一个循环类型。
Nonetheless, having done that, let's look at what I'm going to do. I now want to run a loop where I need to collect things together.
尽管如此,讲完了这些,让我们去看看,我将要进行的操作,我想要运行一个,需要把东西收集起来的循环,我要命名它。
On line 2, we're gonna induce what's called a loop, so do you wanna go ahead and Philip henceforth you get to stare, stare at the awkwardness.
第二行,我们将介绍什么叫做循环,你想接着往下读吗,飞利浦正盯着你看,略显尴尬。
Well, you'll know when it crashes, that doesn't help you very much, but you can't always tell whether something's stuck in an infinite loop or whether it's simply taking a long time to compute.
好,你将学到它在什么时候会崩溃,这对你帮助并不大,但是你不能辨别出到底是在一个循环中,有什么东西卡住了呢,还是程序需要很长的时间来计算一个结果呢。
At the end of the first round, I've got the smallest element at the front. At the end of the second round, I've got the smallest two elements at the front, in fact I got all of them sorted out. And it actually runs through the loop multiple times, making sure that it's in the right form.
看看发生了什么,在第一轮结束后,我把最小的元素移到了前面,第二轮结束后,我把最小的,两个元素移到了前面,实际上,所有的元素都排好序了,实际上,这个算法运行了几次循环,确认下这是正确的形式。
And remind you that inside of here, I'd better be changing the variable. All right, if that variable that's counting is not changing I'm going to be stuck in an infinite loop, so I ought to that, right, expect somewhere in there, a change of that variable. All right?
我最好改变了计数器的变量值,好,如果计数的变量没有变化的话,我就会被卡在一个无限循环里面,因此我应该【不可闻的声音】,对,在这里的某个地方,改变下计数器的变量,对不对?我要做的最后一件事情就是?
应用推荐