/*ca50a_c++_break_continue_语句
break语句-打断for{}内部的循环。
1.打断while
2.打断do while
3.打断for
4.打断switch
continue语句-提前结束当次迭代,继续循环
goto语句-60年代开始就禁止使用了!一般不用
srand((unsigned)time(NULL));//用时间来设计随机数的种子
#include <ctime>时间头文件
if (islower(word[0]))//判断是否小写
vs2017,使用ctrl+F5运行
*/
#include <iostream>
#include <vector>
#include <ctime>
#include <string>
using namespace std;
int main()
{
vector<int> vec;
//int r;
srand((unsigned)time(NULL));//用时间来设计随机数的种子
for (int i = 0; i < 10000; ++i)
{
//r = rand() % 101;
//vec.push_back(r);
//cout << r << endl;
vec.push_back(rand() % 100);//rand()随机数
}
cout << "检查是否有人得100分?" << endl;
//for (int j = 0; j < 10000; ++j)
//{
// if (vec[j] == 100)
// break;
//}
vector<int>::iterator iter = vec.begin();
while (iter != vec.end())
{
if (*iter == 100)
break;//打断循环,终止循环
else
++iter;
}
if (iter != vec.end())
cout << "有人得100分" << endl;
else
cout << "没有人得100分" << endl;
//continue例子提前结束当次迭代,继续循环
string word;
cout << "enter some words: ctrl+z to end" << endl;
while (cin >> word)
{
if (islower(word[0]))//判断是否小写
continue;
else
{
cout << "找到一个大写单词" << endl;
cout << word;
cout << ",其长度是:";
cout << word.size() << endl;
}
}
system("pause");
return 0;
}