title: How to draw rectangles using a loop?
body: <p>I need to create a loop which draws rectangles in a vertical line with alternating color (e.g. black, white, black, white). Can anyone tell me how this is done?</p>
  
  <p>I have tried numerous ways but can't seem to get the loop to work, thanks.</p>
  
  <pre><code>for (int x = 0; x&gt;10;x++) {
      int y= 180;
      graph2D.drawRect(170, y, 20, 50);
      y = y + 45;
  }
  </code></pre>
  
  <p>This is what I have, it won't draw the rectangles for some reason and I cant get it to alternate colors.</p>