以下代码具有用户必须输入才能继续代码的预设密码。但是,当输入设置的密码 (PASS1-PASS3) 时,不管怎样,代码都会转到 do-while。我需要做什么才能让 while 认识到密码是正确的,这样它就不会进入无效密码行?
// Program asks user to enter password
// If password is not "home", "lady" or "mouse"
// the user must re-enter the password
using System;
public class DebugFour1
{
public static void Main(String[] args)
{
const String PASS1 = "home";
const String PASS2 = "lady";
const String PASS3 = "mouse";
String password;
String Password;
Console.Write("Please enter your password ");
password = Console.ReadLine();
do
{
Console.WriteLine("Invalid password enter again: ");
password = Console.ReadLine();
} while (password != PASS1 || password != PASS2 || password != PASS3);
Console.WriteLine("Valid password");
Console.ReadKey();
}
}