All right, you can see that this little piece of code, it's got a loop in there, and what's it doing?
好,你们看到的这一小块代码,是做了一个循环吧?,他在做什么?
Did you just Copy and Paste 50 times when you could have just used a loop that cycles 50 times?
你是不是复制粘贴50次,当你可以用一个循环来循环50次呢?
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.
它可能会正确运行,并返回给你一个正确的答案,它可能会崩溃,它可能会一直运行下去,它可能会运行并给你正确的答案。
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时候
We're gonna have a so called a loop, an infinite loop and you actually experience this in the real world.
我们将会做一个循环,一个无限循环,你会在这个,真实世界里体验它。
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.
猫能做的就是一个死循环,并且它能检测我是不是面对着一只鸟,如果没有就转向那只鸟-,它一直不停地追逐这只鸟。
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.
这些饼干人来来回回的移动,还有这些爱心们上上下下地漂浮,都用到我们上周提到过的循环结构,当然还有个声明在里面,就有点像屏幕上,显示的这样。
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秒来等它完成,但是我们使用循环,我们更新一个变量,我们把它排成一个漂亮的格式。
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.
一旦这个条件或这些条件不成立,整个循环终止。
So what I wanted to do is loop back, at least with a couple of things that we see recurring and very understandably so, but let's try to clear up a couple of frequently occurring issues.
所以我想要做的是回环,至少用两三个,我们看到的东西返回,并且可以理解地,让我们试着处理几个,频繁发生的事情。
Once you know what pieces to look for, what mental constructs to reach for, can you realize all right I want to make some dancing figures go back and forth, I need to loop this way and loop this way and check if I'm on the edge and so forth.
一旦确定需要查找的部分,想要达到那种层次,你是否意识到,我想做出一些可以来回走动跳舞的人,我需要按这种方式那种方式让它转圈,并检查我是否,到了屏幕的边缘等等。
I'm going to run through a loop, and I'm going to request some input, which I'm going to read in with raw input.
我要运行一个循环,我需要一些输入,需要读入一些原始的输入。
Which means, next time through the loop, that's going to pop out and return an answer.
循环会跳出并返回这个答案,如果不相等的话。
Then the next thing in the loop, we're going to enter a nested loop and say for every college in the list e, we're going to print the name of the college.
循环中的第二件事,是进入一个嵌套循环,这个嵌套循环将数组中的,大学名字显示出来。
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.
商店里有一个人,现在我们有一个循环,通过这个循环他可以看到我的库存,然后显示出来我实际上都采摘了哪些水果。
Now I have the ability to create a loop, that is, to reuse the same pieces of code over and over again as I go around.
现在我们已经学会如何创建循环了,也就是,重复的一遍又一遍的,执行同一片代码。
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.
我打算跟踪一个小的变量称为,初始值为真,只要它是真的,算法就会继续,但是在循环里,我打算把他设为假,除非交换发生,就把它设为真。
Do nothing, close your loop and then down here do something.
不做什么,关闭你的循环,然后到这里做点事情。
They're inside that loop-I've got the wrong glasses so I'm going to have to squint- and we've got one test which is a comparison we've got another test which is a multiplication-- sorry, not a test, we've got - another step which is a multiplication- and another step that is a subtraction.
他们在循环里面呢,我带错眼镜了所以不得不斜视-,然后我们这里有一个比较的测试,还有一个乘法的测试,-对不起,不是测试,是另外一个乘法的步骤-,还有一个减法的步骤。
And that's very nice, because this allows me to be sure that my FOR loop is going to terminate.
因为这让我确信我的FOR循环是会终止的,因为只要集合是有限的。
Initialization. A very common bug is to initialize a variable. Go through a loop, and then forget to reinitialize it when it needs to be reinitialized again.
忘记初始化,忘记初始化变量是一个很常见的错误,运行完一个循环之后,当需要再次初始化时。
应用推荐