需要一个for循环逻辑用于下面提到的结果 [英] Need a for loop logic for the below mentioned result

查看:45
本文介绍了需要一个for循环逻辑用于下面提到的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现for循环来生成图像动画。如附图所示 http://i.stack.imgur.com/VCjKW.jpg [ ^ ],如果用户选择hbox = 6且vbox = 4,将创建一个包含24个项目的2维数组。现在我们需要按如下方式访问这些元素:





第一次迭代:[1] [1]

第二次迭代:[2] [1],[1] [2]

第3名:[3] [1],[2] [2],[1] [3]
第4名:[4] [1],[3] [2],[2] [3],[1] [4]

第5名:[4] [2] ,[3] [3],[2] [4],[1] [5]

等等,直到最后一次迭代为[4] [6]



所以请给我一个for循环实现来以这种方式访问​​元素。

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.

推荐答案

我只满足你的第四次迭代〔实施例。代码是

i just satisfy upto 4th iterations of your exmaple. The code is
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;
   }
}



但是如果第5次迭代我不清楚变化的部分。在那里我看到对于迭代4和迭代5,行没有相同。这个要求让我很困惑。让我知道代码会对您有所帮助。


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.


这篇关于需要一个for循环逻辑用于下面提到的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆