Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#如何中断内部循环并使外部循环继续使用导致内部循环中断的确切元素?_C# - Fatal编程技术网

c#如何中断内部循环并使外部循环继续使用导致内部循环中断的确切元素?

c#如何中断内部循环并使外部循环继续使用导致内部循环中断的确切元素?,c#,C#,如何中断一个内部循环,并告诉外部循环继续使用导致内部循环中断的确切元素 我不希望外部循环再次通过数组的所有元素 例如: int[] Arr1 = new int[4] { 100, 200, 300, 400 }; int[] Arr2 = new int[3] { 80, 600, 700 }; bool continueLoop = false; for (int j = 0; j < Arr2.Length; j++)

如何中断一个内部循环,并告诉外部循环继续使用导致内部循环中断的确切元素

我不希望外部循环再次通过数组的所有元素

例如:

int[] Arr1 = new int[4] { 100, 200, 300, 400 };

int[] Arr2 = new int[3] { 80, 600, 700 };



            bool continueLoop = false;
            for (int j = 0; j < Arr2.Length; j++)
            {
                for (int i = 0; i < Arr1.Length; i++)
                {
                    if (Arr2[j] < 0) // break condition met?
                    {
                        continueLoop = true; // set a flag to tell the outer loop to continue
                        break;
                    }

                    Arr2[j] = Arr2[j] - Arr1[i];
                    textBox1.Text += Arr2[j].ToString() + Environment.NewLine;

                }
                if (continueLoop) // check if inner loop set continue
                   continue;

            }
期望输出:

80-100 = -20  
600-20 = 580  
580-200 = 380  
380-300 = 80  
80-400 = -320  
700-320 = 380  

通常情况下,这样做:

for(int i = 0;i < array.Lenght; i++)
{
    while(*condition*)
    {
        i++
    }
    //Continue with i in new location
}
for(int i=0;i
展示一个循环示例和您的尝试。下面的答案是猜测你的意思,这就是简单的休息所做的,不是吗?@pinkfloydx33原来的帖子现在更新了:)你的问题仍然没有多大意义。外部循环将继续执行if(continueLoop)检查或不执行if(continueLoop)检查,因为它是循环的最后一条语句。还有更多你想跳过的吗?我注意到这部分没有意义。我只是想测试一些东西,以某种方式获得所需的输出…你知道我如何获得这些值吗?
for(int i = 0;i < array.Lenght; i++)
{
    while(*condition*)
    {
        i++
    }
    //Continue with i in new location
}