I've written a little for loop, which is going to iterate over all of the elements in the list.
让我们先看看这儿的代码,我已经写了一个循环语句,用来迭代处理数组中所有的元素。
Did you just Copy and Paste 50 times when you could have just used a loop that cycles 50 times?
你是不是复制粘贴50次,当你可以用一个循环来循环50次呢?
All right, you can see that this little piece of code, it's got a loop in there, and what's it doing?
好,你们看到的这一小块代码,是做了一个循环吧?,他在做什么?
And there is a self-enforcing loop between the two, where helping others helps ourselves; and helping ourselves, in turn, helps others.
两者间有自我实施的循环,帮助他人就是帮助自己;,帮助自己继而帮助他人。
Well, we say at the top of the loop, when it goes up and comes down the velocity is 0.
在曲线顶端,当物体上升,然后速度为0时候
This is a highly simplified version, but sort of closes the loop on what we've been talking about.
以上是对整个过程的高度概括,但它涵盖了我们讲过的内容
So we'll loop back to this in just a moment, but start by going back earlier in history.
我们稍后会回来继续讨论,先让我们回到早些时候
Condition," this thing in the middle between the semicolons, is going to be checked every iteration of the loop.
条件,“这个在两个分号的中间,它将迭代地检查这个循环的条件。
We're gonna have a so called a loop, an infinite loop and you actually experience this in the real world.
我们将会做一个循环,一个无限循环,你会在这个,真实世界里体验它。
Once each time. Right? I only do one swap potentially, it-- though not one potentially, each time at the end of the loop I do a swap.
每次循环做一次,对么?我其实,就可能做了一次交换,也许并不是可能,每次循环的结束我都得做一次交换。
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.
好的通过生成这个循环,我应该能够达到目的,这也是你们的讲义中下一段代码。
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.
猫能做的就是一个死循环,并且它能检测我是不是面对着一只鸟,如果没有就转向那只鸟-,它一直不停地追逐这只鸟。
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 so the guys in Office Space took that money and they-- -- their for loop-- way too fast is-- was the takeaway in that movie, when they freaked out because they had million dollars or something like that overnight.
所以在办公地点里的家伙才能够搞到钱-,然后利滚利--很快的方法-,这就是整个影片的亮点,当他们出于极度兴奋之中,因为他们已经一夜之间,变成百万富翁了。
You can kind of see where the syntax is going, looks like a loop, but you can kind of put blocks inside of you, and the little arrow suggests that once you get to the bottom just like our socks example, you're gonna do the following again.
从某种程度上你可以看到它的语法构成,像个循环,你也可以把,一些程序块放到循环中,如同短袜的例子,这个小箭头暗示你一旦到达底部,你将会重复接下来的事情。
The cookies were going back and forth and back and forth and the hearts up and down, well, this thing that we had that called a loop last week with a forever block with a statement inside of it is simply gonna look a little something like this.
这些饼干人来来回回的移动,还有这些爱心们上上下下地漂浮,都用到我们上周提到过的循环结构,当然还有个声明在里面,就有点像屏幕上,显示的这样。
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.
恩,这是一个很棒的小搜索,抱歉,和很棒的小排序算法,事实上,它依赖于一些我们要回顾的东西,被称作循环不变量。
printf So here I'm culling printf in a loop again and again, but I'm literally overwriting the previous thing that I wrote.
所以这里我一次次地在循环中使用,但是我逐行地覆盖了我之前所写的东西。
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.
这个小循环是做什么的,这个小的循环是,我要写一个函数或者过程来接受两条消息。
On last week too we saw-- and in your projects you might have seen a so-called repeat loop.
在上个星期-,在你们的工程里面,可能会看到所谓的,“重复循环“
And we won't wait here one hundred seconds for it to finish, but we're using the loop, we're updating a variable, and we're formatting it in a nice way.
我们将不会再这里等待100秒来等它完成,但是我们使用循环,我们更新一个变量,我们把它排成一个漂亮的格式。
It could run and give you the right answer, it could crash, it could loop forever, it could run and apparently give you the right answer.
它可能会正确运行,并返回给你一个正确的答案,它可能会崩溃,它可能会一直运行下去,它可能会运行并给你正确的答案。
By two, by two, by two, and here it just conceptually is why this thing doesn't infinitely loop.
除以2,除以2,除以2,这里只是概念性地说明这一,过程为何不会无限循环。
And I want to remind you, that block of code is a set of instructions, the same set of instructions that are going to be done each time through the loop.
我想提醒大家,这块代码是一个指令集,一个每次循环都会被执行的相同指令集,会变化的仅仅是变量的值。
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.
我们有一个循环,通过一个条件和一个布尔值来判断,是否触到了边缘,还有一些语句,让它回头并咆哮。
And as soon as this condition or these conditions evaluate to false, the whole loop terminates.
一旦这个条件或这些条件不成立,整个循环终止。
应用推荐