Is there any easy way to reference sequential variables in a for loop?

Discussion in 'iOS Programming' started by chaonic, Jul 27, 2008.

  1. chaonic macrumors newbie

    Feb 22, 2008
    Hey guys...

    If I have a bunch of objects named "sq1", "sq2", "sq3", etc. Is there an easy way to reference each from within a for loop?

    For instance, in ActionScript I could do...

    ...or something like that. Is there an Objective-C equivalent?
  2. Encryptic macrumors member

    Jul 27, 2008
    Instead of creating hard-coded variables with names which you wish to access sequentially, create an array. Then you just access them with an index.

    Alternative two, you could create a dictionary of the variables and reference them by string, but that doesn't seem like the best option.
  3. chaonic thread starter macrumors newbie

    Feb 22, 2008
  4. Dippo macrumors 65816


    Sep 27, 2003
    Charlotte, NC
    I second that!
    An array is a data structure consisting of a group of elements that are accessed by indexing and that is what you need to use in this situation.

Share This Page