以下VB程序关于Boolean函数如何解释

来源:百度知道 编辑:UC知道 时间:2024/06/08 21:00:15
Private Sub Comkmand1_Click()
Dim a as Boolean
a = True
If a Then GoTo L1 Else GoTo L2
L1:Print "VB"
L2:Print "VC"
End Sub
程序输出结果为 VB
VC
为什么?
什么叫顺序输出?

程序已经成功跳转到了L1标签处,结果执行完L1行的语句后,程序又顺序执行下去了,你可以这样改

Private Sub Comkmand1_Click()
Dim a as Boolean
a = True
If a Then GoTo L1 Else GoTo L2
L1:Print "VB"
GoTo End
L2:Print "VC"
End:
End Sub

a是个Boolean型变量,值位true,那么if中为真,自然就是到l1处顺序执行
那自然就是输出
VB
VC

Boolean根本不是什么函数

l1只是个标号,转移到那行就顺序输出,知道什么叫顺序吧

你的程序执行到 if那一句后 因为a为真 直接跳到L1
输出 VB
然后继续往下执行 L2
输出 VC
所以结果为vbvc

因为a已经被定义成true了,
所以直接go to l1,
然后再是l2
if a 就是if a(=true),其实很简单的