C# TutorialLesson 15Free preview
C# If...Else
This lesson is part of C# · All levels
Summary
The if structure checks a condition and runs a block of code when the condition is correct, while the else provides a backup line. Many conditions can be arranged in a sequence using the otherwise if. C# also allows for the if to be narrowed, but it should be made less deep so that logic remains easy to read.
Key points
- If (condition) running block when condition is worth true.
- Else if checks the next condition only when the entire previous condition is false.
- Else becomes the last unconditional option, similar to default.
- The condition must produce a bool; numbers cannot be used directly as in the old C language.
- If the bias is to be limited, the logic should be easily tested and treated.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.