Let us see an example program using for loop . This example show how to add sequence numbers using for loop.
Module Example12
Sub main()
Dim StartNum, EndNum As Integer
Dim sum As Integer = 0
Console.Write("Enter Start Number:")
StartNum = Console.ReadLine()
Console.Write("Enter End Number:")
EndNum = Console.ReadLine()
For I As Integer = StartNum To EndNum
sum = sum + I
Next
Console.WriteLine("Sum of " & StartNum & " to " & EndNum & " is :" & sum)
Console.ReadKey()
End Sub
End Module
The above Example add numbers from StartNum to EndNum and produce sum of these sequence numbers.
No comments:
Post a Comment