Objective C loop logic

Posted by Graham on Stack Overflow See other posts from Stack Overflow or by Graham
Published on 2011-01-09T04:33:54Z Indexed on 2011/01/09 8:54 UTC
Read the original article Hit count: 284

Filed under:
|
|

Hi guys,

I'm really new to programming in Obj-C, my background is in labview which is a graphical programming language, I've worked with Visual Basic some and HTML/CSS a fair amount as well. I'm trying to figure out the logic to create an array of data for the pattern below. I need the pattern later to extract data from another 2 arrays in a specific order.

I can do it by referencing a = 1, b = 2, c = 3 etc and then creating the array with a, b, c but I want to use a loop so that I don't have 8 references above the array. These references will be used to generate another generation of data so unless I can get help figuring out the logic I'll actually end up with 72 references above the array.

// This is the first one which gives the pattern

0 0 0 0 (etc) // 1 1 1 1 // 2 2 2 2

NSMutableArray * expSecondRef_one = [NSMutableArray array];

int a1 = 0;
while (a1 < 9) {
    int a2 = 0;
        while (a2 < 8) {
            NSNumber * a3 = [NSNumber numberWithInt:a1];
            [expSecondRef_one addObject:a3];
            a2++;
        }
    a1++;   
}

// This is the second one which I'm stumbling over, I am looking for the pattern

1 2 3 4 5 6 7 8 //
0 2 3 4 5 6 7 8 //
0 1 3 4 5 6 7 8 //
0 1 2 4 5 6 7 8 // etc to -> // 0 1 2 3 4 5 6 7

If you run it in a line every 9th number is -1 but I don't know how to do that over a pattern of 8.

Thanks in advance!

Graham

© Stack Overflow or respective owner

Related posts about arrays

Related posts about loops