Choose with if and else
Check a condition to choose which step runs next.
Simple example
Start2 < 3
Result1
using System;
if (2 < 3) {
Console.WriteLine(1);
} else {
Console.WriteLine(0);
}
1
Advertisements
Everyday examples
A family needs 4 seats. There are 3 left. Show 1 if everyone fits, or 0 if they need another bus.
Start4 → 3
Result0
using System;
int needed = 4;
int free = 3;
if (needed <= free) {
Console.WriteLine(1);
} else {
Console.WriteLine(0);
}
0
Run the example
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson