错误输入后停止并开始

时间:2016-12-01 17:29:03

标签: c# while-loop

我正在学习C#atm并且我不知道如何执行以下操作:

while (points > 0)
{
    String input = Convert.ToString(Console.ReadLine());
    if (input != true)
    {
        Console.WriteLine("wrong number!");
        // here it should stop the following code and start again at the beginning at the while-loop.
    }
    // code if number is correct

喜欢"停止;",感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

continue是您要查找的关键字。进一步阅读:

https://msdn.microsoft.com/en-us/library/923ahwt1.aspx

答案 1 :(得分:0)

使用continue关键字来实现此目标: -

while (points > 0)
{
    string input = Convert.ToString(Console.ReadLine());

    if (string.IsNullOrEmpty(input))
    {
        Console.WriteLine("wrong number!");
        continue;
    }
}