For Loop(C#)内部的递增数字

时间:2019-07-03 10:17:12

标签: c# loops for-loop numbers increment

我有 for循环

private void Test(int myCount)
{
 \\some code

  int x = 3;
  int y = 7;

  for (int k = 1; k < myCount, k++)
  {
      //if k=1 => x =13, y=17
      //if k=2 => x =23, y=27
      //if k=3 => x =33, y=37
      Console.WriteLine(x.ToString());
      Console.WriteLine(y.ToString());
   }
}

我怎么显示x和y 递增?

myCount = 4
------------
13,17
23,27
33,37
43,47

3 个答案:

答案 0 :(得分:1)

似乎您只希望每次运行都将x&y增加10。

private void Test(int myCount)
{
 \\some code

  int x = 3;
  int y = 7;

  for (int k = 1; k < myCount; k++)
  {
      x += 10;
      y += 10;
      Console.WriteLine(x.ToString());
      Console.WriteLine(y.ToString());
   }
}

答案 1 :(得分:0)

您是否希望循环的每次迭代递增10

  for (int k = 1; k < myCount, k++)
  {
      x = x + 10;
      y = y + 10;      
      Console.WriteLine(x.ToString());
      Console.WriteLine(y.ToString());
   }

答案 2 :(得分:0)

其他答案

r(5) { /*code*/ }