欢迎来到山村网

数学代数教学总结

2019-01-29 17:05:47浏览:501评论:0 来源:山村网   
核心摘要:在学习vb过程中,很多同学简单地认为布尔值true就是-1或非0值,false就是0,这种看法是错误,下面将布尔值、逻辑运算和关系运算

在学习vb过程中,很多同学简单地认为布尔值true就是-1或非0值,false就是0,这种看法是错误,下面将布尔值、逻辑运算和关系运算总结如下:

在vb中,布尔(boolean)值有两个:true(真)和false(假),布尔值可以用于逻辑、关系(比较)和算术运算中。

1)布尔值用于逻辑运算中,结果为布尔值。

例如:

print not true, not false

print true and true, true and false, false and true, false and false

print true or true, true or false, false or true, false or false

结果为:

false true

true false false false

true true true false

【总结】

not 非运算规则:非真则假,非假则真

and 与运算规则:只有都是true,结果才为true(只要有一个为false,结果就为false)

or 或运算规则:只有都是false,结果才为false(只要有一个为true,结果就为true)

2)布尔值用于关系(比较)运算中,结果为布尔值。

例如:

print true false

结果为:

false

【总结】在关系运算中,true小于false。

3)布尔值用于算术运算中(true当作-1,false当作0),结果为数值型。

例如:

print true + 3, false + 3

结果为:

2 3

----------------------------------------------------------------------------

1)逻辑运算说明

数值用于逻辑运算中,非0值当作true,0当作false,结果为数值型。

注:true and n和false or n的结果为n,其他情况true写成-1,false写成0(即结果可能为n、-1或0)

例如:

print true and 5, true and 0, false and 5, false and 0

print true or 5, true or 0, false or 5, false or 0

结果为: 5 0 0 0

-1 -1 5 0

【注意】布尔值可用于算术运算;数值可以用于逻辑运算。但不能认为true和-1、false和0完全等价。

● 算术运算的结果必然为数值型。

● 关系运算(比较运算)的结果必然是布尔值。

● 逻辑运算的结果可能是布尔值或是数值型。

2)关系(比较)运算说明

数值、日期、字符和布尔值都可以比较。

● 日期比较的规则是“日期在后的大”

● 字符比较的规则是按照ascii码比较,空格"0"-"9""a"-"z""a"-"z"汉字

● 布尔值比较的规则是假大于真。

例如:

print 3 5

print #9/19/2009# #9/18/2009#

print "abc" "abcd"

print true false

结果为:

true

true

false

false

(责任编辑:豆豆)
下一篇:

会计工作总结

上一篇:

车间研发中心工作总结

  • 信息二维码

    手机看新闻

  • 分享到
打赏
免责声明
• 
本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们 xfptx@outlook.com
 
0相关评论