Exemplos de C# 4 - 012 - continue

using System;

namespace 
_001_003_012_continue
{
    
class Program
    {
        
static void Main(string[] args)
        {
            
int 1;
            int 
qtd 0;

            while 
(x <1000)
            {
                
if (!TestarPrimo(++x))
                    
continue;

                
Console.Write("{0}\t",x);

                
qtd++;
            
}

            Console.WriteLine(
"\n\nQuantidade de primos: {0}", qtd);
            
Console.ReadKey();
        
}

        
private static bool TestarPrimo(int x)
        {
            
bool retorno = true;

            for 
(int 2i < x + 2i++)
            {
                
if (x % i == 0)
                {
                    retorno 
= false;
                    break;
                
}
            }

            
return retorno;
        
}
    }
}

Comentar

  Country flag

biuquote
  • Comentário
  • Pré-visualização
Loading