title: How would I set a limit so it would stop a loop at set amount by user?
body: <p>//counter class used in OPP for with the demo code, it should work with the code supplied but the output is all wrong and the setLimit wont limit anything </p>
  
  <pre><code>public class CounterExtended {
      private int value;
      /**
       * Gets the current value of this counter.
       * 
       * @return the current value
       */
      public int getValue() {
          return value;
      }
  
      /**
       * Advances the value of this counter by 1.
       */
      public void count() {
          value = value + 1;
      }
  
      /**
       * Resets the value of this counter to 0.
       */
      public void reset() {
          value = 0;
      }
  
      public void setLimit(int maximum) {
          if (value &gt;= maximum)
              System.out.printf("Limit of",maximum, "exceeded");
      }
  
  
      public void undo() {
          if (value&gt;=0){
           value--;
          }
  
      }
  }
  </code></pre>
  
  <p>and Democode</p>
  
  <pre><code>public class Demo {
  
          public static void main(String[] args) {
                  CounterExtended tally = new CounterExtended();
                  for (int i = 1; i &lt;= 10; ++i) {
                          if (i &gt; 7) {
                                  tally.setLimit(6);
                          }
                          tally.count();
                          System.out.printf("After count %d, tally is %d\n", i,
                                          tally.getValue());
                  }
                  tally.undo();
                  tally.undo();
                  tally.count();
                  System.out.printf("After 2 undo's and one count, tally is %d\n",
                                  tally.getValue());
  
          }
  
  }
  </code></pre>
  
  <p>AND OUTPUT SHOULD LOOK LIKE AFTER IT RUNS THE CODE ABOVE </p>
  
  <pre><code>After count 1, tally is 1
  After count 2, tally is 2
  After count 3, tally is 3
  After count 4, tally is 4
  After count 5, tally is 5 
  Limit of 5 exceeded
  After count 6, tally is 5 
  Limit of 5 exceeded
  After count 7, tally is 5 
  After count 8, tally is 6 
  Limit of 6 exceeded
  After count 9, tally is 6
  Limit of 6 exceeded
  After count 10, tally is 6
  After 2 undo's and one count, tally is 5
  </code></pre>