In life, you constantly make decisions. If it is raining, you take an umbrella. If you are hungry, you eat. If you are late, you get ready faster.
Software works the same way. A program checks a condition and behaves differently depending on the result. This is called a decision structure.
bool yagmurYagiyor = true;
if (yagmurYagiyor)
{
Console.WriteLine("Şemsiyeni al.");
}
Without decision structures, programs would react the same way to everyone and every situation. That would make software blind and lifeless.
Think of a login screen: if the password is correct, it should let the user in; if it is wrong, it should show an error. The thing that creates this difference is the if / else logic.
The if part runs when the condition is true. The else part runs when the condition is false.
Think of it like a door system: if your card is valid, the door opens; otherwise, it stays closed.
int yas = 17;
if (yas >= 18)
{
Console.WriteLine("Giriş yapabilirsiniz.");
}
else
{
Console.WriteLine("Giriş yapamazsınız.");
}
Sometimes two options are not enough. Think about a grading system: above 90 is A, above 70 is B, above 50 is C.
In such cases, you use else if. This lets the program check multiple possibilities in order.
int not = 78;
if (not >= 90)
{
Console.WriteLine("A");
}
else if (not >= 70)
{
Console.WriteLine("B");
}
else if (not >= 50)
{
Console.WriteLine("C");
}
else
{
Console.WriteLine("Kaldı");
}
Decision structures look simple, but if they are not written cleanly, they can quickly make code messy. That is why learning a few core rules early is very useful: