title: Break loop inside a delegate
body: <p>I created simple class, which can use to create loops:</p>
  
  <pre><code>public class SimpleLoop
  {
      public int I { get; set; }
      public Predicate&lt;int&gt; Condition { get; set; }
      public int Increment { get; set; }
      public Action&lt;int&gt; Action { get; set; }
  
      public SimpleLoop(int i, Predicate&lt;int&gt; condition, int increment, Action&lt;int&gt; action)
      {
          I = i;
          Condition = condition;
          Increment = increment;
          Action = action;
          Invoke();
      }
  
      private void Invoke()
      {
          for (int i = I; Condition.Invoke(i); i += Increment)
          {
              Action.Invoke(i);
          }
      }
  }
  </code></pre>
  
  <p>Then I can call this loop this way:</p>
  
  <pre><code>new SimpleLoop(0, i =&gt; i &lt;= 12, 1, delegate (int i)
  {
      Console.WriteLine(i);
  });
  </code></pre>
  
  <p>Everything works fine, but I don't know how to break out of the loop, because I can't use the keywords <code>break</code> and <code>continue</code> inside a <code>void</code>. I found out that I can use <code>return</code> to get same effect as <code>continue</code>, but I can't break out of the loop. </p>
  
  <p>I also created other "loop classes" on the base of this class. They look quite similar, but there I use a customized delegate instead of <code>Action</code></p>