根据以下代码,消息框将显示哪个数字?

时间:2016-05-17 02:21:48

标签: vb.net

我有下面的代码,让我知道消息框会显示什么号码?

 for intCount = 1 to 5    
    bytTotal = bytTotal + 1*3    
 Next
 MsgBox intCount.

我是Vb.net的新手并试图解决这个问题。

1 个答案:

答案 0 :(得分:1)

在退出For之前,intCount被赋值为6,大于5,因此退出循环。

以下代码:

Dim intCount As Integer = 0
Dim bytTotal As Integer = 0

For intCount = 1 To 5

    bytTotal = bytTotal + 1 * 3

    Console.WriteLine("Inside for, intcount = " & intCount)

Next

Console.WriteLine("Outside for, intcount = " & intCount)

将输出:

Inside for, intcount = 1
Inside for, intcount = 2
Inside for, intcount = 3
Inside for, intcount = 4
Inside for, intcount = 5
Outside for, intcount = 6

https://dotnetfiddle.net/tagt0z

因此,如果您要将第二个Console.WriteLine替换为MessageBox.Show,则会显示6。