while循环嵌套for循环,当for循环过程中某一值不变时,退出while循环,可采取以下方案:
int previousCounter = counter;
while (true)
{
foreach (var item in ols)
{
if (CanJoin(item, firstline) && !visited.Contains(item))
{
visited.Add(item);
counter += 1;
// 如果JoinEntity改变了firstline或其他重要状态,请在这里更新它
}
}
if (counter == previousCounter)
{
break;
}
previousCounter = counter;
}