# Answer to Question #50432 in Visual Basic for Bender

Question #50432

What is the value of sum after the following code is executed? Why?

Dim sum As Integer = 5

For i As Integer = 1 To 5

sum += i

Next

Dim sum As Integer = 5

For i As Integer = 1 To 5

sum += i

Next

Expert's answer

Answer

Initial condition:

sum=5

Loop for sum

for i=1:5

sum=sum+i

end

Answer sum=20

Initial condition:

sum=5

Loop for sum

for i=1:5

sum=sum+i

end

Answer sum=20

## Comments

## Leave a comment