VBA中以下代码的输出是什么?

时间:2018-01-07 05:11:01

标签: vb.net vba

这个问题在去年的考试中得到了提问。我不认为它会因<>这句话而给出输出。你有什么想法?

Dim sum As Integer, k As Integer
sum = 0
k = 5
Do While k <> 0
    sum = sum + k * k
    MsgBox "sum" & sum
    k = k - 1
Loop

3 个答案:

答案 0 :(得分:0)

是的,它会提供$('sliderStatus').each(function(){ $(this).val(); }); 的输出。它将从55循环到k=5k=1将在每个循环中以sum的结果递增:

k*k

准确地说,根本就没有输出,但会有五条弹出消息:

sum = 0  + 5 * 5 = 25
sum = 25 + 4 * 4 = 41
sum = 41 + 3 * 3 = 50
sum = 50 + 2 * 2 = 54
sum = 54 + 1 * 1 = 55

答案 1 :(得分:0)

写:

Sub test()
    Dim sum As Integer, k As Integer
    sum = 0
    k = 5
    Do While k <> 0
        sum = sum + k * k
        Debug.Print "K" & k & " - " & "sum" & sum
        k = k - 1
    Loop
End Sub

输出结果为:

K5 - sum25
K4 - sum41
K3 - sum50
K2 - sum54
K1 - sum55

在即时窗口中显示( Ctrl + I

答案 2 :(得分:0)

输出将是你的程序

sum25
sum41
sum50
sum54
sum55