← C# Programming learning path
C# Programming · Module 3 of 10

Control flow and methods

Make decisions, loop and organise code into methods.

📖 Key ideas

  1. if/else, switch and switch expressions.
  2. Loops: for, foreach, while, do-while.
  3. Methods: static int Add(int a, int b) => a + b;
  4. Optional and named parameters.
  5. out and ref pass variables by reference.
💡 Real-life example: Methods are recipes: write once, cook many times with different ingredients.
foreachLoops over a collection
switch expressionConcise switch returning a value
MethodNamed reusable code block
out parameterReturns extra values via argument