我有下面的代码,让我知道消息框会显示什么号码?
for intCount = 1 to 5
bytTotal = bytTotal + 1*3
Next
MsgBox intCount.
我是Vb.net的新手并试图解决这个问题。
答案 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。