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.

3 Answers 3

19
continue; // Goto the next iteration break; // Exit the loop 
Sign up to request clarification or add additional context in comments.

2 Comments

+1 Clear and concise; exactly what I like to see in an answer.
That is why I marked it as the answer. It can't get any clearer than that.
5

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

Comments

1

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.