输出语句两次后如何继续while循环?

时间:2016-04-02 20:45:46

标签: c# while-loop switch-statement

我只能将switch语句循环两次。在第二次控制台关闭后,无论我从开关盒中选择了什么选项。我应该如何修改我的代码,以便用户可以继续循环切换案例直到他们决定停止?

感谢您的建议。

int userChoice = 0;

Console.WriteLine("This is an application. It has many different modes.");
Console.WriteLine("You can activate the mode of the application, which can be inserting, retrieving, printing, saving or uploading.");
Console.WriteLine("Type 'I' to insert, 'R' to retrieve, 'P' to print, 'S' to save, 'U' to upload the data, or 'T' to terminate the application.");

string mode = Console.ReadLine();

switch (mode)
{
    case "I":
        Console.WriteLine("You have chosen to insert the data.");
        break;                        

    case "R":
            Console.WriteLine("You have chosen to retrieve the data.");
            break;

    case "P":
        Console.WriteLine("You have chosen to print the data.");
        break;

    case "S":
        Console.WriteLine("You have chosen to save the data.");
        break;

    case "U":
        Console.WriteLine("You have chosen to upload the data.");
        break;

    case "T":
        Console.WriteLine("You have chosen to terminate the application.");                      
        return;                        
}

// Two modes, quit option
if (mode == "I" || mode == "R")
{
    Console.WriteLine("The application will stay in the insert or retrieve modes. Press 'Q' to exit to the modes to return to the main menu.");
}   

while (userChoice != 0)
{
    Console.WriteLine("Please choose one of the modes {0}.", userChoice);                
            userChoice++;
}

Console.WriteLine("Type 'I' to insert, 'R' to retrieve, 'P' to print, 'S' to save, 'U' to upload the data, or 'T' to terminate the application.");
Console.ReadLine();

1 个答案:

答案 0 :(得分:1)

看起来你想要这样的东西(伪代码)

ng-repeat="item in items | orderBy : '[]': true"