2

In my application I chose one integer type variable name counter.

int counter;

which is used to increase different values. but in some condition I want to stop the increasing value

if (counter > totalImageCount) {
            NSLog(@"counter:%d",counter);
            counter = counter - 8;
}

and I don't have any idea how to stop the value of this counter. In above if condition I want to add one more condition like if the value of the counter = 100 at that time I want to stop the counter but I don't know how to stop the counter. plz tell me how can I stop

iPhone
  • 4,092
  • 3
  • 34
  • 58

2 Answers2

1

I think you looking for something like this;

bool dobreak = false;
for ( ..; !dobreak && ..; .. ) {
   for ( ... ) {
      if (...) {
         dobreak = true;
         break;
      }
   }
}

From How can I break out of two nested for loops in Objective-C?

Community
  • 1
  • 1
Daniel Magnusson
  • 9,541
  • 2
  • 38
  • 43
0

You can use one more if condition inside your if block like:

if (counter > totalImageCount) {
     if( counter >100)
          break;
     NSLog(@"counter:%d",counter);
     counter = counter - 8;
}

or you can use if(counder>totalImageCount && counter<100)

halfer
  • 19,824
  • 17
  • 99
  • 186
DShah
  • 9,768
  • 11
  • 71
  • 127