/*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;
}