0

How to put condition for an array to display the images. if it encounters last element of array it should go to previous order i.e., consider array have some 5 elements. 0 1 2 3 4 i need to traverse from 0 1 2 3 4 after encounter 5th object now to it should traverse to 4 3 2 1 0. How to put this logic?

iPatel
  • 46,010
  • 16
  • 115
  • 137
chaithraVeeresh
  • 258
  • 3
  • 11

2 Answers2

0

I just put my logic

for(int i = 0 ; i < myArray.count; i ++)
{
  NSLog(@"%d", i);
  if(i == myArray.count -1)
  {
    for(int j = myArray.count-1 ; j >= 0; j --)
    {
       NSLog(@"%d", j);
    }
  }
}

Try with it, its working well. :)

iPatel
  • 46,010
  • 16
  • 115
  • 137
0

The easiest way is doing 2 loops.

for (NSInteger i = 0;i < [array count]; i++)
{
    NSLog(@"%@", [array objectAtIndex:i]);
}

for (NSInteger i = [array count] - 1;i >= 0; i--)
{
    NSLog(@"%@", [array objectAtIndex:i]);
}
Gonzo
  • 1,533
  • 16
  • 28