The following code is supposed to take input from the user and print out each entry and add them together with a final print out of the total of all input numbers. The code does exactly that, but I don't get how it prints each input without the writeline being inside the loop. If I move the writeline into the loop, it double prints the input. Any help understanding this would be greatly appreciated. Thanks
Sub Main()
Dim sum As Integer
Dim inValue As Integer
Console.WriteLine("Enter a number: ")
Do
inValue = Console.ReadLine()
If inValue <> -1 Then
sum += inValue
End If
Loop Until inValue = -1
Console.WriteLine(sum)
Console.WriteLine("press enter to exit")
Console.ReadLine()
End Sub
Module Module1
Sub Main()
Dim sum As Integer
Dim inValue As Integer
Do
Console.Write("Enter a number: ")
inValue = Console.ReadLine()
If inValue <> -1 Then
sum += inValue
End If
Loop Until inValue = -1
Console.WriteLine("Sum: {0}", sum)
Console.WriteLine("press enter to exit")
Console.ReadLine()
End Sub
End Module
Comments
Leave a comment