title: When/How to replace a for loop with foreach
body: <p>I am creating an integer set class where the object can hold up to 101 numbers through a boolean array. My assignment is to use foreach loops whenever possible, but I can't quite find a place where I can use it / where it would even make sense to use it.</p>
  
  <p>Here are some snippets of my code, and I did the program exactly as my teacher asked. I can't quite figure out union set into a foreach loop if it is even possible. Can this program be improved by a foreach loop, and if so, where?</p>
  
  <pre><code>public bool[] set = new bool[101];
  
  public IntegerSet(){
  
      for (int k = 0; k &lt; set.Length; k++)
      {
          set[k] = false;
      }
  
  public IntegerSet unionSet  (IntegerSet a)
  {
      IntegerSet c = new IntegerSet();
      for (int i = 0; i &lt; 101; i++)
  
      {
          if (a.set[i] == true || this.set[i] == true)
              c.set[i] = true;
      }
  
      return c;
  }
  
  public bool isEqual(IntegerSet a)
  {
      int count = 0;
      for (int i = 0; i &lt; 101; i++)
      {
          if (a.set[i] == this.set[i])
              count++;
      }
      if (count == 101)
          return true;
      else
          return false;
  }
  </code></pre>