0

I have multiple foreach loops in my program which I want to break one of the inner loops at a certain met condition.

I know in Java you can give it some sort of label, and then when the condition is met you write break LabelName

Is there something similar to it in C#? I read there was something goto but goto is pointing to go somewhere to continue performing methods rather than just breaking the loop.

Sample code in Java:

STOPLOOP : for(Clause c : clausesList)
            {
                // Random Coding
                            if(!l.solved(hasExcl))
                            {
                                literalCanBeRemoved = false;
                                c.complete = false;
                                break STOPLOOP 
                            }
Marek Kwiendacz
  • 9,524
  • 14
  • 48
  • 72
DodoSombrero
  • 767
  • 3
  • 15
  • 29
  • 2
    remove all that and use LINQ. [C#](http://www.footballshootball.com/wp-content/uploads/2014/01/Ferrari-of-Lionel-messi.jpg) is not [java](http://img4.wikia.nocookie.net/__cb20100213022144/inciclopedia/images/e/ee/Caballo-Carro.jpg). – Federico Berasategui Jul 24 '14 at 18:23
  • @HighCore Just gave an example of what I meant in case I didn't explain myself very clearly. – DodoSombrero Jul 24 '14 at 18:25
  • @HighCore - a very good argument to dump that crappy old C# for F#. – H H Jul 24 '14 at 18:46
  • It is a valid question, nested loops still have a role in C#. It's just not original enough. – H H Jul 24 '14 at 18:46
  • This is a university assignment I'm doing as a SAT Solver (DPLL) where I have multiple foreach loops to check clauses and the literals. Most of the questions I found all have a for loop rather than foreach though I think I can alter it. – DodoSombrero Jul 24 '14 at 18:50
  • in my days, we were first thought pascal, then Java in Highschool and we branch out in Uni to C, C# and C++, .NET and so. now we just phased out Pascal. Problem is, they do not actually teach you what's behind the language, the pros, cons, strong type, when and for what to use. Mostly just give you an assignment and leave you puddling to it – DodoSombrero Jul 24 '14 at 19:20
  • @HighCore This is not a place for the discussion of languages. If you don't have anything to contribute to the question, then it's time to move on. – mason Jul 24 '14 at 20:35

0 Answers0