Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.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#,我有这样的代码: main() { for(i=0;i<100;i++) { if(cond1) func(1); //Just some logics are present here if (cond2) if(cond3 | cond4) func(2); and so on.... } } void func(int) { do somthing; if cond5 continu

我有这样的代码:

main()
{
   for(i=0;i<100;i++)
   {
   if(cond1)
       func(1); //Just some logics are present here
   if (cond2)
      if(cond3 | cond4)
          func(2);
and so on....
   }
}

void func(int)
{
   do somthing;
   if cond5
      continue;// this is for the FOR loop in main() & I know this doesnt make sense.
}
main()
{

对于(i=0;i从函数中返回bool并继续false。使用您的示例:

main()
{
   for(i=0;i<100;i++)
   {
   if(cond1)
       func(1); //Just some logics are present here
   if (cond2)
      if(cond3 | cond4)
          if (!func(2))
             continue;
and so on....
   }
}

bool func(int)
{
   do somthing;
   if cond5
      return false;
   return true
}
main()
{

对于(i=0;i从函数中返回bool并继续false。使用您的示例:

main()
{
   for(i=0;i<100;i++)
   {
   if(cond1)
       func(1); //Just some logics are present here
   if (cond2)
      if(cond3 | cond4)
          if (!func(2))
             continue;
and so on....
   }
}

bool func(int)
{
   do somthing;
   if cond5
      return false;
   return true
}
main()
{
对于(i=0;i
  • 将func函数返回类型更改为bool,以便在满足条件时返回true,否则返回false
  • 在for循环中检查func返回值。如果是try-调用continue。否则-不执行任何操作

    void main()
        {
           for(i=0;i<100;i++)
           {
            if(cond1)
               if (func(1))
                   continue;//Just some logics are present here
           if (cond2)
              if(cond3 | cond4)
                  if (func(2))
                      continue;
            and so on....
           }
        }
    bool func(int)
    {
        do somthing;
        bool bRes = false;
        if cond5
            bRes = true;// this is for the FOR loop in main() & I know this doesnt make sense.
        // ....
        return bRes;
    }
    
    void main()
    {
    对于(i=0;i
    
  • 将func函数返回类型更改为bool,以便在满足条件时返回true,否则返回false
  • 在for循环中检查func返回值。如果是try-调用continue。否则-不执行任何操作

    void main()
        {
           for(i=0;i<100;i++)
           {
            if(cond1)
               if (func(1))
                   continue;//Just some logics are present here
           if (cond2)
              if(cond3 | cond4)
                  if (func(2))
                      continue;
            and so on....
           }
        }
    bool func(int)
    {
        do somthing;
        bool bRes = false;
        if cond5
            bRes = true;// this is for the FOR loop in main() & I know this doesnt make sense.
        // ....
        return bRes;
    }
    
    void main()
    {
    
    对于(i=0;i)我的答案很好,但您可能已经添加了一些关于如何更改(改进)程序流的文本。回答很好,但您可能已经添加了一些关于如何更改(改进)程序流的文本。