I am stuck on a c# issue where I cant get the while loop to end.
userValue is a string that is input earlier on in the program.
The string is formatted in DateTime, and the new input need to match the original userValue. I.E Confirming the the users original birth date.
I used a try / catch to determine if the input can be parsed to DateTime.
Currently it is just a constant loop, i'm trying to have the loop stop once the users birth date is verified.
string userValueTwo;
int stop = 0;
while (stop != 0)
{
Console.WriteLine("Please verify your birth date");
userValueTwo = Console.ReadLine();
try
{
DateTime birthdayTwo = DateTime.Parse(userValueTwo);
}
catch
{
Console.WriteLine("You did not enter a valid format.");
Console.ReadLine();
}
if (userValueTwo == userValue)
{
Console.WriteLine("Birth date confirmed.");
Console.ReadLine();
}
else
{
Console.WriteLine("Your birthday did not match our records. Please try again");
Console.ReadLine();
}
}
stopor callbreakso it can't exit the loop.DateTime.TryParseinstead of using an Exception to capture the failure of parsing.stop = 0;thenstop != 0should always result in false if there's nothing in between.break;command or let the while loop know that the condition has been met to terminate. In general,while (condition==true) { this.do(something); }loops continue forever until your condition becomes false. That won't happen arbitrarily; you need to set that condition to false, somehow.