Given the following code what number will the message box display?

Before exiting the For, intCount gets assigned the value 6, which is greater than 5, and therefore exits the loop.

The following code:

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)

Will output:

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

So if you were to replace the second Console.WriteLine by MessageBox.Show, it would display 6.

Leave a Comment