如何在 C 的 switch case 中使用 case 返回菜单

How to go back to menu using case in switch case in C

如何在不使用 GOTO 命令的情况下使用 switch case 中的 case 返回菜单。所以这是示例:

while(1){
  printf("1: Basic Math\n2. Intermediate Math\n3. Advance Math");
  printf("Enter your choice: ");
  int choice;
  scanf("%d", &choice);

  switch(choice)
    int theChoices;
    case 1:
      printf("1. Add\n 2. Subtract\n3. Go back to menu");
      scanf("%d", &theChoices);

      switch (theChoices) {
         case 1:
           //calculation ...
         case 2:
           //calculation ...
         case 3:
           // Go Back to menu which is Basic math, Intermediate Math, Advance math
           // ***** I want to know how do i get back to the main menu. *****
    case 2:
    // ....
// ....................

所以我的问题又是如何使用案例 3 返回菜单。当我尝试使用关键字 break 时,当我选择案例 3 时它会自动关闭程序。请帮忙。

改用continue;。它会跳出所有case,继续执行它们之后的代码,这样程序就会return到while (1)之后的第一行。不要忘记用 break;.

结束每个 case