Visual Basic 中的决策语句与循环结构详解
1. 决策语句中的 OR 逻辑运用
在 Visual Basic 里,我们可以借助 OR 运算符(Or)来实现 OR 逻辑的决策语句。下面是一个示例代码:
Dim medicalPlan As String = "Y"
Dim dentalPlan As String = "N"
If medicalPlan = "Y" Or dentalPlan = "Y" Then
System.Console.WriteLine( _
"Employee has medical insurance" & _
" or dental insurance or both.")
Else
System.Console.WriteLine( _
"Employee does not have medical" & _
" insurance and also does not have dental insurance.")
End If
在这个例子中,变量 medicalPlan 被初始化为字符串常量 “Y”, dentalPlan 被初始化为 “N”。当计算 medicalPlan = "Y" 这个表达式时,结果为 True;计算 dentalPlan = "Y" 时,结果为 False。由于使用的是 OR 逻辑,只要其中一个表达式的计算结果为 True,整
超级会员免费看
订阅专栏 解锁全文
3

被折叠的 条评论
为什么被折叠?



