for(item)
{
for(criterion)
{
if(!item.ismetby(criterion))
{
next item loop//as one criterion not met, while continue can only continue to next criterion loop?
}
}
}
for(item)
{
for(criterion)
{
if(!item.ismetby(criterion))
{
next item loop//as one criterion not met, while continue can only continue to next criterion loop?
goto: continuei
}
find itemi
break;
}
<span style="white-space:pre"> </span>break;
continuei: continue;
}
shortage: use goto, but maybe sometimes, especially multi loop it's more appropriate
for(item)
{
bool foundflag=true;
for(criterion)
{
if(!item.ismetby(criterion))
{
next item loop//as one criterion not met, while continue can only continue to next criterion loop?
foundflag=false;
}
}
if(foundflag==true)
{
find itemi;
break;
}
//continuei: continue;
}
shortage: if one criterion not met, can not stop criterion instantly for next item loop
for(item)
{
if(Allmet(item[i], criterion[]))
{
found itemi;
break;
}
}
shortage: execute efficientcy is effected, but that does not effect much, maybe.
continue break 只能對當前loop奇效,continue是指當前不滿足某條件,不用繼續當前循環,直接下一層loop了,有點剪枝的味道,break則是滿足了某條件,可以直接退出循環,也有點剪枝的味道,但是也包含找到正確解如果不break可能解錯了