So even though we think of conditions as being Boolean values true or false, really underneath the hood true means anything other than zero.
即使我们考虑,布尔值的真假条件,在底层“真“表示非零。
false It's going to return true if it's a PAIL-indrome and false if it's a PAL-indrome. And it says true. Now maybe you're bugged by this.
如果不是会问的话则是,返回的是真值,那么你可能会觉得这个很烦。
If you want to make sure both conditions are true and they both have to be true for any code to be executed, use ampersand ampersand.
如果你想保证两个条件都成立,或者它们两个都必须为真值,才能执行一些代码,那就使用“&&“
Notice by the way, there's that nice speck true going on saying put a string here.
在这里说放一个字符串在这儿有点小问题,如果是回文的话那么它将会返回真值。
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.
我打算跟踪一个小的变量称为,初始值为真,只要它是真的,算法就会继续,但是在循环里,我打算把他设为假,除非交换发生,就把它设为真。
So I can return true here.
所以我可以在这儿返回真值。
Knowing that, I'm going to say, OK, how many pigs are there, well that's just how we're, however many I had total, minus that amount, and then I can see, how many legs does that give, and then I can check, that the number of legs that I would get for that solution, is it even equal to the number of legs I started with, ah! Interesting. A return.
它将给我返回头的总数,知道了这些之后我可以说好了,有多少猪呢,无论有多少组鸡的数目,我只要用总数减去那个值,之后我就可以知道一共有多少条腿,然后再把这个值和题目中的腿数相比较,看它是否等于一开始的腿数,啊!真有趣,有一个返回值。
We say, ah, that's now true.
我们说的是现在应该返回真值了。
All right, it's so if I looked at it, sorry, IF x is less than y, THEN check to see IF x is less than z, and if that's true, print out x is the smallest.
好,代码是这样的,对不起,是不是x比y小,然后去看看是不是x比z小,如果都为真的话,显示x为最小值。
应用推荐