And in the middle of this blank slate, in the middle, this is where my program is going to go.
中间是空白,是程序执行的地方。
And the robot or the computer or what have you is just automatically, mechanically following the code commands of the program.
那些机器人,或叫做计算机等等,只是自动地,机械地执行程序的命令代码
OK. Having done this now, I can simply go ahead and run this, and in fact if I go up here to run, you'll see I've got both an option to check the module, though in this case I'm just going to run it.
好,讲完了这些,我可以去执行程序了,实际上如果我在这里运行,你们会看到我同样得到了,一个可以同时检查模块的选项,虽然在这个例子中我就是直接去运行程序了。
So what we would see, I'm going to completely fake this, is a program that operates like that.
所以我们会看到,我要完全掩盖这一点,就好像程序真的是那样执行的。
Is it some kind of procedure standard operating procedure that you follow?
是不是有一定的程序,标准的执行程序呢,然后你就按照那个程序?
With simple branching, how long is it going to take to run a piece of code?
但是在简单分支程序中,执行一个程序,要多长时间呢?
What that means, in a stored-program computer, is that I can provide to the computer a sequence of instructions describing the process I want it to execute.
它的意思就是说,我可以给一个存储程序计算机,提供一系列,描述我希望,能执行的过程的指令。
What I mean by that is, pick a simple set of values, and let's walk through it to see what happens. And this is useful because it's going to allow me to A make sure that I've got something that's going to terminate, it's going to let me make sure that in fact I'm doing the right kinds of updates.
原因你们知道的,好,模拟代码,我的意思就是,选出一系列的值来,然后模拟下代码的执行来看看结果,这很有用因为这让我确保我的程序在某个地方,可以终止,还会让我确保实际上我。
I'm not wasting time typing out arguments and implementing more complicated function.
我不会在浪费时间在打印输出参数上,我执行了更复杂的程序。
We might say, even if we are smart enough to build programs that can, by mechanistically following the program, do things we've never thought of.
我们或许说,即使我们非常聪明,可以编制些,能够机械地执行指令的程序,做一些我们从来没想到的事情
Having reached the end of the block, go back up and check the test.
执行到了这块代码的最后,程序会回去再做一次测试。
What is it about the thought that the computer is just following a program?
电脑仅仅只是在执行程序,这个观点到底是什么样的
So this program, if you run it based on intuition or little cheat sheets in front of you, what is this program ultimately going to do for me?
所以这个程序,如果你按照你的直觉,或你们面前的备忘单来执行它,这个程序最终会为我做什么?
So in your mind, if you are now the computer program and you are executing this thing from top to bottom, what just has happened verbally is we are stepping into the line of code that says sort left half of elements.
在你们看来,如果你现在是计算机程序,正在从上到下执行一系列指令,刚才所发生的就是我们现在已执行到了这行代码,它告诉你要对左半部分的元素排序。
It's a little puzzle piece that says when the green flag is clicked and this is kind ; of like the beginning of a program; when you double click an icon on your desktop this is how something like that is implemented; it's listening for that double click, it's listening for that green flag.
是一小个按钮,它的意思是,何时点击绿色旗帜,这就好比开始运行程序;,当你双击桌面上的图标,就开始执行操作,桌面的图标需要双击,绿色小旗也等待点击来执行命令。
Simply walk down that list.
执行一个直线序列的程序。
Even if we could build a program, even if we had built programs that can be creative, that can do things that nobody's thought of before, all the program is doing is following its program, right?
即使我们能编写一个程序,即使我们已经编写出具有创造力的程序,它们可以做一些从来没有人想到过的事情,程序所做的只不过是执行程序,对吗
But literally all I can do at this stage is write what we would call a straight-line program, that is, a program in which we execute in which we execute the sequence of instructions one by one.
但是字面上来说,我们现在学到的,都是所谓的直线程序,也就是,一个接一个的执行,一系列的,指令的程序。
In Scratch you may have realized that, "I could implement my program this way with these puzzle pieces, but it kind of feels -- like I could use these puzzle pieces instead" -- that's absolutely the case in programming.
在Scratch中你可能已经意识到,“我可以用这一段代码来,执行我的程序,不过这有点感觉到,我可以用这些代码段来代替“,那绝对是编程中的一个情况。
At the end of the day, you can implement the exact same program using a while loop that you can using a for loop, it's just your code is going to look slightly different.
最终,你可以执行这个程序,再使用for循环的地方使用while循环,这只是使你的代码看起来稍微有点不同。
Still all the computer can do, all the robot can do is automatically, necessarily, mechanically follow the program.
即便如此,电脑所能做的,机器人所能做的,只是自动地必然地机械地执行程序
So we want to write programs to do that.
为了实现这一目标我们要去写一个执行程序。
Now this happens to be what we would call a linear process, because the number of times I go around the loop is directly related to the size of the argument. If I double 2 the argument, I'm going to double the number of times I go around the loop. If I increase it by five, 5 I'm going to increase by five the number of times I go around the loop.
这恰好是我们会成为,线性复杂度程序的一个例子,因为我要执行循环的次数是,和输入的参数的大小直接相关的,如果我将这个参数乘以,那么我就要将进行循环的次数也乘以2了,如果我把参数加上,那么循环的次数也要加上5了。
Go ahead and implement with the person next to you a program that takes as input from the user an integer called F and prints out the answer of the Celsius equivalent.
继续和你旁边的人执行程序,取来自用户的整数F作为输入,然后打印出与之等价的摄氏温度的答案。
It ran through that sequence of instructions, in particular it bound x to the value three, x and then it took x times x, got the value of x multipied by x, which of course is nine, bound that to the value of x, and then it printed out the value, and now it's sitting here waiting for an input.
程序按照指令的顺序去执行的,首先是把x和3这个值进行了绑定,然后把x乘以,得到了x乘以x的值,当然也就是9了,然后把x和这个值进行了绑定,然后显示出这个值,然后就等待输入。
So what's going to happen here? If I'm inside this FOR, OK, and I'm running around, if I ever hit a place where this test is true, I'm going to execute that return, return that return returns from the entire procedure. OK? So the return comes back from the procedure.
那么这里发生了什么呢?,如果我是在这个for循环里面,我正在运行,如果我运行到test的值为真的地方,我就会执行,这个return将会返回整个程序的值,明白了吗?所以它将会从整个程序中返回值。
But notice what this does. The first thing it does is, it says, let's check and make sure x is greater than or equal to 0. If it isn't, notice what's going to happen. None of that block is going to get executed, and it's going to come down here and print out a useful piece of information, which says, hey, you gave me a negative number. I don't know how to do this.
做的是和以前一样的事情,但是注释它做了什么,第一件做的事情就是,程序说,要去检查并且确信x是大于等于0的,如果不是的话,请注意会发生什么,下面的代码都不会被执行,程序会到这里来然后显示一些有用的信息,信息会说,嘿,你给了我一个负数,我不知道该怎么弄这个了。
应用推荐