主题:请大家帮忙看看
using System;
using System.Collections.Generic;
using System.Text;
namespace inputCapitalLetter
{
class Program
{
static void Main()
{
[color=FF0000]bool ok = false; [/color]
while (ok == false)
{
Console.Write("请输入5个大写字母:");
string str = Console.ReadLine();
if (str.Length != 5)
{
Console.WriteLine("你输入的字符个数不是5个,请重新输入。");
}
else
{
ok = true;
for (int i = 0; i < 5; i++)
{
char c = str[i];
if (c < A || c > Z)
{
Console.WriteLine("第{0}个字符“{1}”不是大写字母,请重新输入。", i + 1, c);
ok = false;
break;
}
}
}
}
}
}
}
请问bool ok = false;在程序里有什么作用?
这样的好处是什么?
谢谢
using System.Collections.Generic;
using System.Text;
namespace inputCapitalLetter
{
class Program
{
static void Main()
{
[color=FF0000]bool ok = false; [/color]
while (ok == false)
{
Console.Write("请输入5个大写字母:");
string str = Console.ReadLine();
if (str.Length != 5)
{
Console.WriteLine("你输入的字符个数不是5个,请重新输入。");
}
else
{
ok = true;
for (int i = 0; i < 5; i++)
{
char c = str[i];
if (c < A || c > Z)
{
Console.WriteLine("第{0}个字符“{1}”不是大写字母,请重新输入。", i + 1, c);
ok = false;
break;
}
}
}
}
}
}
}
请问bool ok = false;在程序里有什么作用?
这样的好处是什么?
谢谢