C:我如何在代码中打破这个循环?

0 c loops break repeat

我之前看过stackoverflow上的问题,但这是我第一次问,所以我提前为任何格式错误道歉.我已经在C编程上上了大约一个月的课程,并且我已经被赋予了在我的main函数中使用do/while循环来循环displayMenu()的赋值,它允许用户输入1, 2,或3显示某一块信息.

int main(void)
{
    int option = 0;
    do
    {
        option = displayMenu();
    } 
    while (option ==  displayName() || displayColor() || displayFood());
}

//Display the menu for choosing an option or exiting the program
int displayMenu()
{
    int choice = 1;
    while (choice == 1 || 2 || 3)
    {
        puts("Choose which piece of information you would like to know:");
        printf("%s", "1 - My name, 2 - My favorite color, 3 - My favorite food\n");
        printf("%s", "Or type in any other number to exit the program:  ");
        scanf("%d", &choice);
        puts("");

        if (choice == 1)
            displayName();
        if (choice == 2)
            displayColor();
        if (choice == 3)
            displayFood();
    }
    return choice;
}
Run Code Online (Sandbox Code Playgroud)

现在,我确定错误是在这两种方法中的某个地方,但为了以防万一,我正在发布显示方法.

//Function to display my name
int displayName()
{
    int value = 1;
    puts("My name is x.\n");
    return value;
}

//Function to display my favorite color
int displayColor()
{
    int value = 2;
    puts("My favorite color is y.\n");
    return value;
}

//Function to display my favorite food
int displayFood()
{
    int value = 3;
    puts("My favorite food is z.\n");
    return value;
}
Run Code Online (Sandbox Code Playgroud)

如果用户输入1,2或3,则程序正确显示信息并循环以再次提示用户输入另一个值.但是,如果输入任何其他数字,程序会再次提示用户输入一个值,而应该关闭程序.我究竟做错了什么?我试过插入一个

else return choice;
Run Code Online (Sandbox Code Playgroud)

在前三个if语句之后,因为我认为需要打破循环,但它没有用.它与我的条件有关吗?我不确定我的条件是否正确,(关于==和||优先级等等),所以如果有人能澄清它也会很好.我知道有可能更有效的方法来执行这个程序,但我只限于我在课堂上学到的东西,这实际上不是我编码的东西.

oua*_*uah 5

while (choice == 1 || 2 || 3)
Run Code Online (Sandbox Code Playgroud)

相当于

while ((choice == 1) || 2 || 3)
Run Code Online (Sandbox Code Playgroud)

这相当于

while (1)
Run Code Online (Sandbox Code Playgroud)

你想要的是:

while (choice == 1 || choice == 2 || choice == 3)
Run Code Online (Sandbox Code Playgroud)