Stage 1 · Lesson 4 of 9
Conditionals and loops
(if, else if and else) choose between paths. switch statements and the newer switch expressions pick between many cases without bugs, for example var grade = score switch { >= 90 => "A", >= 80 => "B", _ => "C" };.
Use a when you need a position number, and foreach (var name in names) to walk every item. Use a while loop when you do not know the count. break leaves a loop and continue skips a pass.
Conditions must be bool (true or false), so if (count) does not compile when count is an int. That removes a class of bugs other languages have. Trace loops on paper, especially where they start and stop, because i <= list.Count throws ArgumentOutOfRangeException on the last pass.
A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- GuideFreeLearn C#
Microsoft · Beginner
Official C# fundamentals tutorials that you run locally with the .NET SDK
- PlatformFreefreeCodeCamp
freeCodeCamp · Beginner
Free Foundational C# certification, built with Microsoft, with a graded exam at the end