GoTo statements, and alternatives (help me please im new) (VB.net)

Posted by qais on Stack Overflow See other posts from Stack Overflow or by qais
Published on 2010-04-23T17:14:27Z Indexed on 2010/04/23 17:23 UTC
Read the original article Hit count: 320

Filed under:
|
|
|

Basically I posted a code snippet on a forum asking for help and people pointed out to me that using GoTo statements is very bad programming practise so I'm just wondering, why is it bad?

And also what alternative is there to use, like for example in this program ive done for homework the user has to input their date of birth and if the month/date/year are invalid or unrealistic(using if statements checking the integer inputs size, if theres any better way to do this i'd appreciate if you could tell me that also :D) then how would i be able to loop back to ask them again? heres a little extract of my code

retryday:
    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")
        GoTo retryday
    End If

© Stack Overflow or respective owner

Related posts about homework

Related posts about vb.net