设有下面的语句:Print IIf(x>0,1,Ilffx

admin2015-05-29  23

问题 设有下面的语句:Print IIf(x>0,1,Ilffx<0,-1,0))与此语句输出结果不同的程序段是

选项 A、If x>0 Then
    x=1
    Elselfx<0 Then
    x=-1
    End If
    Print x
B、Ifx>0 Then
    Print 1
    Elselfx<0 Then
    Print-1
    Else
    Print 0
    End If
C、 Select Case x
    Case Is>0
    Print 1
    Case Is<0
    Print-1
    Case Else
    Print 0
    End Select
D、Ifx<>0 Then
    Ifx>0 Then
    Print 1
    Elselfx<0 Then
    Print-1
    Else
    Print 0
    End If
    End If

答案D

解析 IIf函数可用来执行简单的条件判断操作,它是“If…then…Else”结构的简写版本。格式为:Result=IIf(<条件>,,)。当<条件>为真时,IIf函数返回,而当<条件>为假时,返回。本题中IIf函数的功能是判断x是不是正数,如果是返回1,否则继续判断a是不是负数,如果是返回-1,否则返回0,即返回x的符号。分析4个选项只有D选项不应该使用Elself语句而应该使用Else语句。
转载请注明原文地址:https://kaotiyun.com/show/CCQp777K
0

最新回复(0)