break

noun

say it: “BRAYK” /breɪk/

A statement that leaves the nearest loop or switch straight away.

What does break do in C#?

break — A statement that immediately exits the nearest loop or switch.

class NumberFinder
{
    int FirstOdd(int[] numbers)
    {
        foreach (int number in numbers)
        {
            if (number % 2 == 0)
            {
                continue;
            }

            return number;
        }

        return -1;
    }
}

In a sentence

  • “The loop uses break as soon as it finds the book we're looking for.”

Level: Apprentice · More C# terms at this level

Updated

In other subjects