break跳出离它最近的循环。如while、for

验证输入的五个字母是否为大写。

public static void Main(string[] args)
        {
            Console.WriteLine("请输入五个大写字母:");
            while (true) {//死循环,直到正确输入
                bool a = true;
                string str = Console.ReadLine();//输入默认为字符串。若为int数据,则Convert.ToInt32(str);
                for (int i = 0; i < 5; i++) {
                    if (str[i] >= 'A' && str[i] <= 'Z') {//字符是以int数据存储的,字符等效数据
                        //空语句,无动作
                    } else {
                        a = false;
                        break;//一旦有小写字母,跳出for循环
                    }
                }
                if (a == true) {
                    Console.WriteLine("输入正确");
                    break;//跳出while循环
                } else {
                    Console.WriteLine("有小写字母,输入有误,请重新输入");
                }
            }
            Console.ReadKey();
        }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-13
  • 2021-06-10
  • 2022-01-25
  • 2022-12-23
  • 2021-04-11
  • 2021-10-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
  • 2021-11-09
相关资源
相似解决方案