I've posted a code snippet on another forum asking for help and people pointed out to me that using
Console.WriteLine("Please enter the day you were born : ")
day = Console.ReadLine
If day > 31 Or day < 1 Then
Console.WriteLine("Please enter a valid day")
I'm going to differ from everyone else and say that GOTOs themselves are not all the evil. The evil comes from the misuse of GOTO.
In general, there is almost always better solutions than using a GOTO, but there really are times when GOTO is the proper way to do it.
That being said, you are a beginner, so you shouldn't be allowed to judge if GOTO is proper or not (because it hardly ever is) for a few more years.
I would write your code like this (my VB is a bit rusty...):
Dim valid As Boolean = False While Not valid Console.WriteLine("Please enter the day you were born: ") Dim day As String day = Console.ReadLine If day > 31 Or day < 1 Then Console.WriteLine("Please enter a valid day.") Else valid = True End If End While
If you take your GOTO code and look at it, how would someone first approach your code? "Hmm.. retryday? What does this do? When does this happen? Oh, so we goto that label if the day is out of range. Ok, so we want to loop until the date is considered to be valid and in range".
Whereas if you look at mine:
"Oh, we want to keep doing this until it's Valid. It is valid when the date is within range."