Efficiency of grid generated by for-in loop I've spend the last several hours working on a loop designed to take items in an array and arrange them as a so to speak "gird" of UIButtons. As far as I've been able to see through testing this code works perfectly.

However, I am new to creating loops and I was wondering if anyone could give me any pointers on how I could make this code cleaner/more efficient for future coding purposes.

I know my question is very similar to Optimize sorting of Array according to Distance (CLLocation), but I'm really hoping to get some tips on a "per case" basis. Thank you for your time.

- (void)myMethod
{
    NSArray *array = [[NSArray alloc] initWithObjects:@"Item #1", @"Item #2", @"Item #3", @"Item #4", @"Item #5", @"Item #6", @"Item #7", @"Item #8",  nil];

    BOOL leftOkay = NO;
    BOOL centerOkay = NO;
    BOOL rightOkay = NO;
    int left = 0;
    int center = 1;
    int right = 2;
    int yOrigin = 0;
    int spaceBetweenItems = 5;
    UIButton *leftButton;
    UIButton *centerButton;
    UIButton *rightButton;

    for (int i = 0; i &lt; [array count]; i++)
    {
        if (left &lt; [array count]) {
            leftButton = [[UIButton alloc] initWithFrame:CGRectMake(spaceBetweenItems, yOrigin + spaceBetweenItems, 100, 150)];
            [leftButton setTitle:[array objectAtIndex:left] forState:UIControlStateNormal];
            [leftButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
            [leftButton setBackgroundColor:[UIColor cyanColor]];
            [myScrollView addSubview:leftButton];
            leftOkay = YES;
        }
        if (center &lt; [array count]) {
            centerButton = [[UIButton alloc] initWithFrame:CGRectMake(110, yOrigin + spaceBetweenItems, 100, 150)];
            [centerButton setTitle:[array objectAtIndex:center] forState:UIControlStateNormal];
            [centerButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
            [centerButton setBackgroundColor:[UIColor yellowColor]];
            [myScrollView addSubview:centerButton];
            centerOkay = YES;
        }
        if (right &lt; [array count]) {
            rightButton = [[UIButton alloc] initWithFrame:CGRectMake(215, yOrigin + spaceBetweenItems, 100, 150)];
            [rightButton setTitle:[array objectAtIndex:right] forState:UIControlStateNormal];
            [rightButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
            [rightButton setBackgroundColor:[UIColor purpleColor]];
            [myScrollView addSubview:rightButton];
            rightOkay = YES;
        }
        if (leftOkay == YES &amp;&amp; centerOkay == YES &amp;&amp; rightOkay == YES) {
            yOrigin = yOrigin + leftButton.frame.size.height + (spaceBetweenItems * 2);
            leftOkay = NO;
            centerOkay = NO;
            rightOkay = NO;
        }

        left    = left    + 3;
        center  = center  + 3;
        right   = right   + 3;
    }
    myScrollView.contentSize = CGSizeMake(myScrollView.frame.size.width, yOrigin + leftButton.frame.size.height + (spaceBetweenItems * 2));
}
you can write this code dramatically shorter like 

self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

NSArray *array = [[NSArray alloc] initWithObjects:@"Item #1", @"Item #2", @"Item #3", @"Item #4", @"Item #5", @"Item #6", @"Item #7", @"Item #8",  nil];

NSUInteger buttonWidth = 100;
NSUInteger buttonHight = 100;
NSUInteger spacer = 5;
NSUInteger leftOffset = 5;
NSUInteger topOffset = 5;
[array enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
    int row = idx / 3;
    int column = idx %3;

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake((buttonWidth + spacer)*column+leftOffset, (buttonHight+spacer)*row +topOffset , buttonWidth    , buttonHight);
    [button setTitle:obj forState:UIControlStateNormal];
    [self.view addSubview:button];
}];


Note: ARC enabled