Simplifying loop in Objective-C

Posted by Joe Habadas on Stack Overflow See other posts from Stack Overflow or by Joe Habadas
Published on 2012-06-06T10:08:59Z Indexed on 2012/06/06 10:40 UTC
Read the original article Hit count: 280

Filed under:
|
|

I have this enormous loop in my code (not by choice), because I can't seem to make it work any other way. If there's some way make this simple as opposed to me repeating it +20 times that would be great, thanks.

for (NSUInteger i = 0; i < 20; i++) {
     if (a[0] == 0xFF || b[i] == a[0]) {
         c[0] = b[i];
         if (d[0] == 0xFF) {
             d[0] = c[0];
         }

         ... below repeats +18 more times with [i+2,3,4,etc] ...

         if (a[1] == 0xFF || b[i + 1] == a[1]) {
             c[1] = b[i + 1];
             if (d[1] == 0xFF) {
                 d[1] = c[1];
             }

           ... when it reaches the last one it calls a method ...

           [self doSomething];
           continue;
           i += 19;

          ... then } repeats +19 times (to close things)...
      }
   } 
}

I've tried almost every possible combo of things that I know of attempting to make this smaller and efficient. Take a look at my flow chart — pretty huh? i'm not a madman, honest.

flowin' oldskool style

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about loops