Search code examples
language-agnosticloopsgotocontinue

Continue Considered Harmful?


Should developers avoid using continue in C# or its equivalent in other languages to force the next iteration of a loop? Would arguments for or against overlap with arguments about Goto?


Solution

  • I think there should be more use of continue!

    Too often I come across code like:

    for (...)
    {
       if (!cond1)
       {
          if (!cond2)
          {
              ... highly indented lines ...
          }
       }
    }
    

    instead of

    for (...)
    {
       if (cond1 || cond2)
       {
          continue;
       }
    
       ...
    }
    

    Use it to make the code more readable!