tags:

views:

183

answers:

3

In my "native" programming language (RPG), I can write a loop and just leave the loop or force an iteration. It is kind of like a GOTO.

dow (x < 999);
  read file;
  if (%eof);
    leave; // Leave the loop
  endif;
  if (field <> fileField);
    iter; // Iterate to the next record
  endif;
enddo;

My question is if there is a similar option is C#. In my case, I am working with a foreach loop.

+11  A: 
continue; // Goto the next iteration
break; // Exit the loop
Adam Wright
+1 Clear and concise; exactly what I like to see in an answer.
Carl Manaster
That is why I marked it as the answer. It can't get any clearer than that.
Mike Wills
+3  A: 

Break will exit the loop. Continue will jump to the next iteration.

jeffamaphone
A: 

Use the continue keyword

for (int i = 1; i <= 10; i++) 
  {
     if (i < 9) 
        continue;
     Console.WriteLine(i);
  }

the output of this is :

9
10
Glen