【发布时间】:2017-03-14 14:18:16
【问题描述】:
所以基本上我正在尝试编写一个控制台应用程序,它要求用户输入密码,并且将继续要求它仅三遍,然后停止使用“while”循环,但它继续循环即使使用了正确的密码并且在我输入了超过 3 次之后,也会要求我输入密码。
const string pass = "Password";
string attempt;
do
{
Console.Write("Please enter password: ");
attempt = Console.ReadLine();
if (attempt == pass)
{
Console.WriteLine("Access granted.");
}
else
{
Console.WriteLine("Access denied.");
}
} while (true);
【问题讨论】:
标签: c# while-loop passwords console-application limit