Lesson contents

Check after the first turn

Do the work once, then decide whether another turn is needed. The first value is always printed.

Simple example

Print, then test.

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

int number = 1;
do {
    Console.WriteLine(number);
    number++;
} while (number <= 3);
Output
1
2
3
Advertisements

Everyday examples

Print the first waiting ticket even if nobody else is in line. The last ticket today is 41.

StartFirst 41 · last 41
Result41
Program.cs
using System;

int ticket = 41;
do {
    Console.WriteLine(ticket);
    ticket++;
} while (ticket <= 41);
Output
41
Run the example
Terminal
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson
Official documentation