Examples of errors detected by the V3020 diagnostic.

V3020. An unconditional 'break/continue/return/goto' within a loop.


.NET Core Libraries (CoreFX)

V3020 An unconditional 'return' within a loop. Enumerable.cs 517


public override bool MoveNext()
{
  switch (state)
  {
    case 1:
      _enumerator = _source.GetEnumerator();
      state = 2;
      goto case 2;
    case 2:
      while (_enumerator.MoveNext())
      {
        current = _selector(_enumerator.Current);
        return true;
      }
      Dispose();
      break;
  }
  return false;
}

Identical errors can be found in some other places:

  • V3020 An unconditional 'return' within a loop. JsonDataContract.cs 128

Space Engineers

V3020 An unconditional 'continue' within a loop. Sandbox.Game MyRenderComponentThrust.cs 109


public override void Draw()
{
  ....
  foreach (var flame in m_thrust.Flames)
  {
     if (m_thrust.CubeGrid.Physics == null)
      continue;
    ....
    if (m_landingEffect != null)
    {
      m_landingEffect.Stop(true);
      m_landingEffect = null;
      --m_landingEffectCount;
    }
    continue;                    // <=
    ....
    if (m_landingEffect == null)
      continue;
    ....
  }
}

FlashDevelop

V3020 An unconditional 'break' within a loop. AirWizard.cs 1760


private void ExtensionBrowseButton_Click(....)
{
  ....
  foreach (var existingExtension in _extensions)
  {
    if (existingExtension.ExtensionId
      == extensionId) extension = existingExtension;
  break;
  }
  ....
}

Mono

V3020 An unconditional 'throw' within a loop. System.Data.Linq-net_4_x XmlMappingSource.cs 180


public void ReadEmptyContent(XmlReader r, string name)
{
  ....
  for (r.MoveToContent();
         r.NodeType != XmlNodeType.EndElement;
           r.MoveToContent())
  {
    if (r.NamespaceURI != DbmlNamespace)
      r.Skip();
    throw UnexpectedItemError(r); // <=
  }
  ....
}

Media Portal 2

V3020 An unconditional 'break' within a loop. XmlCacheProvider.cs 433


public TvdbSeries LoadSeriesFromCache(int seriesId)
{
  ....
  foreach (TvdbEpisode e in series.Episodes.Where(....))
  {
    if (epImageFile.Contains("thumb"))
      e.Banner.LoadThumb(Image.FromFile(epImageFile));
    else
      e.Banner.LoadBanner(Image.FromFile(epImageFile));
    break;
  }
  ....
}


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;