For Each Loop in Visual Basic: IndexOutOfRangeException [closed]

Assuming you mean VB.NET, array indices range from 0 to the array upper bound of 4 which you exceed at the last index. If you wish to sum the elements you could do

For Each n As Integer In intNum
    tot = tot + n
Next

Leave a Comment