But if I did have two lines of code or more, I would in fact need to put those back.
但是如果我的确有两行或更多的代码,我其实应该把花括号加上。
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.
实际上,这个例子可以编译,因为你可以用这种方式来压缩代码行,但是请认识到,那个,不太好。
Ten lines of code. Twenty lines of code.
用10来行代码,20来行代码就可以。
It's just a series of lines of code.
那只不过是一系列一行行的代码
I'm gonna zoom in a little more and notice it's pretty much 1, 2, 3, 4, 5, 6, 7, 8, 9 lines of code and that's kind of rounding up because of the white space.
我现在放大一点,大家会看到,2,3,4,5,6,7,8,9行代码,多亏了空格,这些代码才能看起来如此美观。
It's deliberate that a lot of the examples in lecture are fairly short and bite-size so that you can actually focus on pulling out the key ideas without getting distracted by line and lines of code.
很多的演讲中的例子,是短小的,因此你们可以集中于提取其中的主要思想,而不是被一行行的代码给分心。
Because if I don't specify a name for this input, I have no way of actually referring to it in subsequent lines of code.
因为如果我不给这个输入定义一个名字,在随后的代码中,我就没有办法使用它。
You need multiple lines of code, you need these days to use something called a scanner class.
你需要写许多代码,你要学会使用扫描仪。
At least you maybe finding that and if not when you look back at the code you then have written you'll realize that in fact it just requires a few lines of code.
至少你会发现这一点,不然的话,在你写完代码,返回去,看的时候你会意识到,实际上它只需要几行代码。
And so what I was hinting at earlier when you put semicolons in the wrong place, and then proceed to have curly braces around arbitrary lines of code, you're creating an even more local scope there, which is generally not the right intended behavior.
在之前我暗示了,当你把一个分号放在错误的地方时,然后开始用花括号,括上任意行的代码,你在那里创建了一个局部范围,那个不是故意的行为。
And when I'm starting to write lots of lines of code, you know, it's frankly kind of useful to be able to see more on the screen at once without having to scroll.
当我开始写很多行代码的时候,你们懂的,这明显是有用的,当你可以在屏幕上看到更多的代码,而不用滚动屏幕。
And, in fact, it kind of looks like a function, and yet here's a semicolon I just said that can get you into trouble, and yet that's not actually a function, because there's no interesting lines of code, because it turns out the interesting code is down here at the bottom.
实际上,它有点像一个函数,并且这里有一个能够使你陷入麻烦当中的分号,那个事实上也不是一个函数,因为这里没有有用的代码,因为,有用的代码都在底端。
Delete those lines of code and move them up to the top and problem solved.
把这几行代码删除,然后把它们放到,前面去,问题就解决了。
The curly braces to encapsulate one or more lines of code.
花括号压缩了一行或多行代码。
You can imagine having many lines of code where all of a sudden your closed quote is on the next line all the way on the left.
你可以想象一下,这有很多行代码,突然一个后引号,移到下一行最左边。
So input is an int called F, print out to the screen or your piece of paper the value of C. Odds are you only need two, maybe three lines of code for this, but the goal ultimately will be try it on your own.
所以输入是一个int类型的F,在你的屏幕上,或你们的纸上打印出C的数值,可能你们需要两行或者三行的代码,但是最终的目标需要你自己独自尝试。
So this line or these lines of code up here are arguably constant time steps to say if N is less than 2 in return, that it will always take maybe one step, maybe two steps, some number of fixed CPU cycles.
如果N小于2并返回,那么这些行所对应的代码,通常只需要执行一步,或者两步,具体数字与CPU周期有关。
So the very last two lines of code I'm saying this, s2 the original string is s1, the copy of the string is s2, but if I haven't lost you, what are we really going to see when we print this?
最后两行代码是这样的,原字符串是s1,那个字符串的拷贝是,但是如果我没有忘记,当我们打印的时候,我们将看到什么?
But what looks like this orange block as of now in Scratch, add orange to your so called inventory, well, it's gonna take at least two lines of code in C to actually create the inventory array with this first line and then put something like the word orange inside of it.
就好比Scratch里面橘色的这一块,把“桔子“加到所谓的“清单“里面去,在C语言中至少需要两行代码来实现,第一行代码创建一个货单数组,第二行就需要把“桔子“放进去。
As an aside, if you ever just have one line of code that you want to execute, one puzzle piece in Scratch terminology, ; you actually don't need the curly braces; you only need the curly braces if you have two or more lines of code that you want to execute if that condition is true.
此外,如果你只有一行代码,需要执行,在Scratch,术语中叫做,一句代码,你就不需要使用花括号了;,如果那个条件成立,你有两行或更多行的代码时需要执行时,你就需要花括号。
So here is the simplest program which is perhaps an ironic statement that you can implement with this language called C. So it takes a few lines of code to actually get something up and running and as you'll recall last Friday, I didn't even get this up and running because part of the process of writing a program is to one, write it.
让我们回到这个最简单的程序,你们也许觉得啼笑皆非,这么简单的例子,用C语言写出来就可以了嘛,的确只需要几行代码,就可以让这个程序跑起来,就像上周五的那样,我之所以没让它跑起来,因为编程步骤之一,就是“写“
Imagine instead, you're writing code that's a hundred thousand lines, a million lines, of code. You don't want to write it in this form. All right, and the reason you don't want to do that is, well, several.
换一个角度来思考,你正在写的代码有几十万行,近百万行,你绝对不想写成这种格式,好吧,你不想这么做的原因有以下几个。
So in other words, if you terminate these lines early, if you terminate the four loop early, if you terminate an if condition early with that semicolon, the code may very well work; and this is a common source -- of frustration and conundrum because you don't -- because your code looks right and yet it's misbehaving, but that semicolon means stop looking for subsequent lines of related code.
换句话说,如果你用分号过早的终止了这些代码行,如果你过早地终止了那个for循环,如果如此,一个if条件,代码可能可以运行,这就是,挫折和问题产生的源头,因为你没有-,因为你的代码看起来是正确的,但是运行是错误的,那个分号的意思是,停止寻找后面相关的代码。
应用推荐