Simplifying loop in Objective-C
- by Joe Habadas
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.