2: Conditions 条件
We now know how we can define variables and give them different values, and we can even do some basic math, but that’s it. In this tutorial, you’ll learn how to check variables to be equal to something, greater than, and so forth. We do this using another set of operators: the relational operators:
到目前为止,我们已经是知道了如何定义一个变量,并且可以利用变量进行一些简单的数学运算了。
现在,我们来学习比较。
比较就是比较一下两个东西之间的关系,和进行数学运算一样的,进行比较运算同样也需要用到对应的比较运算符,比如说有如下几种:
== Equal to 比较是否左边和右边相等
> Greater than 比较是否左边大于右边
< Less than 比较是否左边小于右边
>= Greater than OR Equal to 比较是否左边大于或者和右边相等
<= Less than OR Equal to 比较是否左边小于或者和右边相等
!= NOT Equal to 比较是否左边和右边不相等
We use this with a variable or number/string/int/etc on the left, and what you want to check for on the right.
比较的结果有且只有两种情况,要么是是,也就是true(真),要么是不是,也就是false(假,或者说伪)。
我们来看下面的几个例子:
We can also do this with variables, like so:
我们同样也可以直接用变量来进行比较,请看下面的这几个例子:
We now know how we can define variables and give them different values, and we can even do some basic math, but that’s it. In this tutorial, you’ll learn how to check variables to be equal to something, greater than, and so forth. We do this using another set of operators: the relational operators:
到目前为止,我们已经是知道了如何定义一个变量,并且可以利用变量进行一些简单的数学运算了。
现在,我们来学习比较。
比较就是比较一下两个东西之间的关系,和进行数学运算一样的,进行比较运算同样也需要用到对应的比较运算符,比如说有如下几种:
== Equal to 比较是否左边和右边相等
> Greater than 比较是否左边大于右边
< Less than 比较是否左边小于右边
>= Greater than OR Equal to 比较是否左边大于或者和右边相等
<= Less than OR Equal to 比较是否左边小于或者和右边相等
!= NOT Equal to 比较是否左边和右边不相等
We use this with a variable or number/string/int/etc on the left, and what you want to check for on the right.
比较的结果有且只有两种情况,要么是是,也就是true(真),要么是不是,也就是false(假,或者说伪)。
我们来看下面的几个例子:
We can also do this with variables, like so:
我们同样也可以直接用变量来进行比较,请看下面的这几个例子: