for instance, let's say I want to do something like this:
bool foo(List<strings> stringList, int counter)//assume this list has, like, 10 elements, and counter=3, idk
{
bool found= false;
for(int i=0; i<stringlist.Count && !found; i++)
{
if(stringlist[i].length < 2 || counter >=6)
found=true;
counter++;
}
return found
}
Now, Is that equivelent to this:
bool foo(List<strings> stringList, int counter)//assume this list has, like, 10 elements, and counter=3, idk
{
bool found= false;
foreach(string s in stringlist.Takewhile(x=> (!found)))
{
if(s.length < 2 || counter >=6)
found=true;
counter++;
}
return found
}
Does this second example behave like the first, or does it always skip the whole loop? As a follow up, if I still want to use a foreach, do I really have to use a break to get around this? Also, sorry if I did something dumb in these examples, I am trying to simplify a version of a path-finding algo I am writing and this was the simplest example I could think of to ask this question...