Click here to Skip to main content
15,908,674 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to implement a for loop to generate an image animation. As shown in the attached imagehttp://i.stack.imgur.com/VCjKW.jpg[^] , if a user selects hbox=6 and vbox=4, an a 2-d array of 24 items will be created. Now we need to access these elements as follows:


1st iteration: [1][1]
2nd iteration: [2][1], [1][2]
3rd: [3][1],[2][2],[1][3]
4th: [4][1],[3][2],[2][3],[1][4]
5th: [4][2],[3][3],[2][4],[1][5]
and so on until the last iteration is [4][6]

So please provide me a for loop implementation to access the elements in such fashion.
Posted
Updated 17-Feb-13 6:38am
v2
Comments
Sergey Alexandrovich Kryukov 17-Feb-13 12:57pm    
This is not a good question. You need to explain what you try to achieve clearly. Please understand that example is not a formulation of a problem.
—SA

1 solution

i just satisfy upto 4th iterations of your exmaple. The code is
C#
int hbox = 6;
int vbox = 4;
for (int r = 1; r <= hbox; r++)
{
   int x = 0;
   for (int c = 1; c <= vbox; c++)
   {
      string val = arr[r - x, c];
      x++;
      list.Add(val);
      if (r == c)
          break;
   }
}

But if 5th iteration i do not clear the varying part. There i saw row no is still same for iteration 4 and iteration 5. This requirement is little confused me. let me know the code will help you or not.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900