for (iterator i = list.begin(); i != list.end(); ++i)
{
if (i == "[Somehting I want to find]")
{
break;
}
}
// Do sth with i;
========================================================
bool bFound = false;
iterator i = list.begin();
while (!bFound && (i != list.end()))
{
if (i == "[Somehting I want to find]")
{
bFound = true;
}
}
if (bFound)
{
// Do sth with i;
}
我个人很憎恶从循环中用break或return或continue。但使用while又无形中多了一个条件判断语句。没办法,天地本不全,代码也难全呀。
你们怎么看?谢谢。
{
if (i == "[Somehting I want to find]")
{
break;
}
}
// Do sth with i;
========================================================
bool bFound = false;
iterator i = list.begin();
while (!bFound && (i != list.end()))
{
if (i == "[Somehting I want to find]")
{
bFound = true;
}
}
if (bFound)
{
// Do sth with i;
}
我个人很憎恶从循环中用break或return或continue。但使用while又无形中多了一个条件判断语句。没办法,天地本不全,代码也难全呀。
你们怎么看?谢谢。