* break、return、continue、exit
* break -- 跳出switch语句或提前从循环中退出 // 语句级
* continue -- 开始一下次循环的执行 // 语句级
* return -- 将对CPU的控制权交给调用它所在函数的上一级 // 函数级
* exit() -- 终止程序 // 文件级
* OS: Windows XP
* Programming Language: C++
* Compiler: Dev-C++ 4.9.9.2
* Date: 14:28 2009-12-7
*/
using namespace std;
#define FALSE 0
#define TRUE 1
{
unsigned int ia = INIT_VALUE, ib = INIT_VALUE;
unsigned char c_level = INIT_VALUE;
cin >> c_level;
for (ia = 0; ia < 3; ia++)
{
if ('q' == c_level)
{
cout << "You have selected to stop." << endl;
exit(1); // 终止程序的运行,一下的所有指令不再执行。
}
else if ((c_level >= 'A') && (c_level <= 'E'))
{
break; // 程序在此处推出for循环,继续执行for循环以下的语句
}
else
{
cout << "Invalid character, try again" << endl;
cin >> c_level;
if (ia >= 2)
{
cout << "Sorry, you have inputed three time, and all of them were invalid character, the program will stop." << endl;
exit(1); // 终止程序的运行,一下的所有指令不再执行。
}
}
}
flag = GetFlag(c_level);
if (flag)
{
switch (c_level)
{
case 'A':
cout << c_level << " means the score is [90,100]" << endl;
break; /* 跳出switch语句,不再执行switch语句中剩余的部分,而是执行main()函数中switch语句之后的指令 */
case 'B':
cout << c_level << " means the score is [80,90)" << endl;
break;
case 'C':
cout << c_level << " means the score is [70,80)" << endl;
break;
case 'D':
cout << c_level << " means the score is [60,70)" << endl;
break;
case 'E':
cout << c_level << " means the score is [0,60)" << endl;
break;
default:
break;
}
}
cout << "Done!" << endl;
system("pause");
return 0; // 将控制权返还给操作系统,到此,程序运行结束。
}
{
unsigned char loc_flag;
cout << "Do you want to kown what does " << c_level << "means " <<"('y' or 'n')" << endl;
cin >> loc_flag;
while ((loc_flag != 'y') && (loc_flag != 'n') && (loc_flag != 'Y') && (loc_flag != 'N'))
{
cout << "Invalid input try again: ";
cin >> loc_flag;
}
if (('y' == loc_flag) || 'Y' == loc_flag)
{
return TRUE; /* 执行此语句后GetFlag()把对CPU的控制权返还给调用它的main()函数, 此后GetFlag()中的代码不再执行,而是去执行main() 函数中GetFlag()调用处之后的语句。*/
}
else
{
return FALSE;
}
}