I'm trying to get some practise on C# ready for my time constrained test in 2 weeks time, and have been trying to complete exercises I've found in books & on the internet.
The exercise asked to use a while loop to ask a user to enter their name, and if it was not "XXX" then it can continue to loop. But the problem I've got is, after writing the loop, it just continues, there is no way the user can enter "XXX" to stop the program, so I was wondering if anyone knew the solution to this?
Here is the code i've wrote so far..
String sName;
//Declaring the variable
Console.Write("Enter a name (or XXX to end): ");
sName = Console.ReadLine();
//Prompting user to enter the name or to end the program by telling them to type XXX
while (sName != "XXX")
{
Console.Write("The Name is: " + sName);
Console.WriteLine();
}
//Start loop
Console.WriteLine("You are now past the while loop");
//If XXX is typed, message is displayed
Console.WriteLine("Press any key to close");
Console.ReadKey();
//Prevent program from closing
sNamewill never equal "XXX". How do you expect the loop to exit if the condition is never met? :) - TimsName = Console.ReadLine();within the loop. - Candide