布尔逻辑对你规划条件语句的结构特别有用。
Boolean logic is especially useful for formulating clear conditional statements.
我们有一个循环,通过一个条件和一个布尔值来判断,是否触到了边缘,还有一些语句,让它回头并咆哮。
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.
上述语句指定了一个表达式,该表达式产生了一个布尔值和一个不返回任何结果的代码块(Unit),这正是while所期望的。
The arguments above specify an expression that yields a boolean value and a block of code that returns nothing (Unit), which is exactly what while expects.
还可以将原子值的这种使用方法扩展到布尔逻辑,利用原子值true和false来标识语句的布尔结果。
Using atoms in this way also extends to Boolean logic, with the availability of true and false atoms to identify the Boolean result of a statement.
if语句支持一个可选的else子句,指示当布尔表达式计算为False时应该处理的程序语句块。
The if statement supports an optional else clause that indicates a block of program statements that should be processed if the Boolean expression evaluates False.
至此,已经看到了if语句可以如何用于根据一个特定布尔表达式的值,来执行两个程序语句块中的其中一个。
Up to this point, you've seen how the if statement can be used to execute one of two blocks of program statements, depending on the value of a particular Boolean expression.
但是第二个if语句计算为True,因为变量i能被125整除(并且not运算符将结果0转换成布尔值True)。
But now the second if statement evaluates True because the variable I is evenly divisible by 125 (and the not operator turns the resulting 0 into a Boolean True).
如何确定正确的号码如果“(”和“)”一个布尔条件语句?
How to determine the right number if "(" and") "for a Boolean if statement?
如何确定正确的号码如果“(”和“)”一个布尔条件语句?
How to determine the right number if "(" and") "for a Boolean if statement?
应用推荐