C# for continue inside foreach

user1085907 picture user1085907 · Jul 25, 2012 · Viewed 7.4k times · Source

Possible Duplicate:
continue and break with an extended scope

i have one problem. I don't know how to call continue for "for" inside foreach.

Code:

for(int i = 0; i < ...; i++)
{
  foreach(´´ .. in ´´)
  {
    if(,,.Value == null)
      // A!
  }
}

And i need replace "A!" for code to continue "for"! Not foreach. I used basic continue but it work just only for foreach.

SOLVED with:

for(int i = 0; i < ...; i++)
{
  bool Ab = false;

  foreach(´´ .. in ´´)
  {
    if(,,.Value == null)
      Ab = true;
  }

  if(Ab)
    continue;
}

Answer

John Gardner picture John Gardner · Jul 25, 2012

if you need to stop the inner loop, and continue the outer loop, you just need a break statement in the inner loop

for(int i = 0; i < ...; i++)
{   
    foreach(var thing in something)   
    {     
        if(thing.Value == null)       
        {
            break; 
        } 
    }

}