title: Conceptual: incrementing inside a while loop
body: <p><strong>The scenario</strong></p>
  
  <p>I am working on a HUD class to aid me in development of an OpenGL project. I want to be able to add new elements onto the screen dynamically (positioning will happen automatically) with the use of an <code>add_element(char*, float)</code> method. Here is the said code:</p>
  
  <pre><code>class HUD {
  public:
      HUD();
      ~HUD();
  private:
      int elements,
          spacing;
  public:
      void add_element(char*, float);
  };
  
  HUD::HUD() : elements(0), spacing(10) {}
  HUD::~HUD() {}
  
  void HUD::add_element(char* string, float value) {
  
      ++elements;
      // .. render to screen .. //
  }
  </code></pre>
  
  <p>The basic idea is: It will position them vertically for me as I continue to add elements.</p>
  
  <p><strong>The problem</strong></p>
  
  <p>The class gets instantiated inside the main function, and the elements get added and drawn to the screen within and at the end of my game loop. This means, every frame, the <code>element</code> counter gets incremented, when it should only increment the first time a unique element is added. I have thought about adding unique identifiers as an argument, like numbering them manually every time I call the method, but this seems to defeat the purpose I am going for. </p>
  
  <p>I am just looking for some ideas that can solve this type of incrementing inside a loop. I have a few scenarios in which I need to do this, and the HUD is the first one I ran into. </p>