Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Practicing break and continue | Loops
course content

Conteúdo do Curso

C# Basics

Practicing break and continuePracticing break and continue

There is a for-loop without a default ending condition. Inside the loop, skip all the even iterations and in case of odd iterations increment the value of oddNumbers. Stop the loop as soon as the value of oddNumbers equals 27. Use break and continue for this purpose.

cs

main.cs

1. A number x is even if it satisfies the condition x % 2 == 0.

using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int oddNumbers = 0;
            for (int i = 0; ; i++)
            {
                if (i % 2 == 0)
                {
                    continue;
                }
                oddNumbers++;
                Console.WriteLine(i);
                if (oddNumbers == 27)
                {
                    break;
                }
            }
        }
    }
}
      

Tudo estava claro?

Seção 4. Capítulo 8
course content

Conteúdo do Curso

C# Basics

Practicing break and continuePracticing break and continue

There is a for-loop without a default ending condition. Inside the loop, skip all the even iterations and in case of odd iterations increment the value of oddNumbers. Stop the loop as soon as the value of oddNumbers equals 27. Use break and continue for this purpose.

cs

main.cs

1. A number x is even if it satisfies the condition x % 2 == 0.

using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int oddNumbers = 0;
            for (int i = 0; ; i++)
            {
                if (i % 2 == 0)
                {
                    continue;
                }
                oddNumbers++;
                Console.WriteLine(i);
                if (oddNumbers == 27)
                {
                    break;
                }
            }
        }
    }
}
      

Tudo estava claro?

Seção 4. Capítulo 8
some-alt