Lesson contents

Continue statement

Skip the rest of one turn and carry on with the next value.

Simple example

Skip two.

Start1 → 3 · skip 2
Result1 3
Program.cs
using System;

for (int number = 1; number <= 3; number++) {
    if (number == 2) {
        continue;
    }
    Console.WriteLine(number);
}
Output
1
3
Advertisements

Everyday examples

Locker 12 is being repaired. List the available lockers from 11 through 13.

Start11 → 13 · skip 12
Result11 13
Program.cs
using System;

for (int locker = 11; locker <= 13; locker++) {
    if (locker == 12) {
        continue;
    }
    Console.WriteLine(locker);
}
Output
11
13
Run the example
Terminal
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson
Official documentation