<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title>ByteDocs</title>
	<subtitle>Practical notes on software development, cloud tools, and learning by building.</subtitle>
	
	<link href="https://bytedocs.vercel.app/feed/feed.xml" rel="self"/>
	<link href="https://bytedocs.vercel.app/"/>
	<updated>2026-01-21T00:00:00Z</updated>
	<id>https://bytedocs.vercel.app/</id>
	<author>
		<name>Filipe Oliveira</name>
		<email>fmo.oliveira@gmail.com</email>
	</author>
	
	<entry>
		<title>C# Recursion and Trampolines</title>
		<link href="https://bytedocs.vercel.app/posts/csharp-recursion/"/>
		<published>2026-01-21T00:00:00Z</published>
				<updated>2026-01-21T00:00:00Z</updated>
		<id>https://bytedocs.vercel.app/posts/csharp-recursion/</id>
		<content type="html">&lt;p&gt;Understanding recursion is a rite of passage for every developer. It’s elegant, mathematically pure, and… dangerous.&lt;/p&gt;
&lt;p&gt;If you’ve ever stared at a &lt;code&gt;StackOverflowException&lt;/code&gt; in C#, you’ve met the dark side of recursion. But there is a concept called &lt;strong&gt;Tail Recursion&lt;/strong&gt; that, in theory, fixes this. While functional languages like F# or Haskell handle this automatically, C# needs a bit of &amp;quot;cleverness&amp;quot; to make it work.&lt;/p&gt;
&lt;p&gt;This guide will break down the concept of tail recursion, why C# struggles with it, and a clever design pattern called the &amp;quot;Trampoline&amp;quot; to make recursion safe.&lt;/p&gt;
&lt;h2 id=&quot;part-1:-the-&amp;quot;stack&amp;quot;-problem&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/csharp-recursion/#part-1:-the-%22stack%22-problem&quot;&gt;&lt;span&gt;Part 1: The &amp;quot;Stack&amp;quot; Problem&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;To understand tail recursion, you first need to visualize the &lt;strong&gt;Call Stack&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Imagine you are reading a book. You find a reference to another book, so you put a bookmark in the current page, open the new book, and start reading. If that book references another, you add another bookmark and open the third book.&lt;/p&gt;
&lt;p&gt;In programming, every time a function calls itself, the computer adds a &amp;quot;bookmark&amp;quot; (called a &lt;strong&gt;Stack Frame&lt;/strong&gt;) in memory to remember where it was (local variables, return address).&lt;/p&gt;
&lt;h3 id=&quot;the-standard-recursive-crash&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/csharp-recursion/#the-standard-recursive-crash&quot;&gt;&lt;span&gt;The Standard Recursive Crash&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Let’s look at a classic recursive calculation: Factorial (5! = 5 * 4 * 3 * 2 * 1).&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// BAD RECURSION&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Factorial&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; n&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;n &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;// The multiplication happens AFTER the recursive call returns.&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// We must &quot;remember&quot; n to multiply it later.&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; n &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Factorial&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;n &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you call &lt;code&gt;Factorial(10000)&lt;/code&gt;, the computer has to remember 10,000 numbers waiting to be multiplied. Eventually, it runs out of bookmark space. Boom: &lt;code&gt;StackOverflowException&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;part-2:-what-is-tail-recursion&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/csharp-recursion/#part-2:-what-is-tail-recursion&quot;&gt;&lt;span&gt;Part 2: What is Tail Recursion?&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Tail recursion&lt;/strong&gt; is a specific way of writing recursion where the recursive call is the absolute &lt;strong&gt;last thing&lt;/strong&gt; the function does.&lt;/p&gt;
&lt;p&gt;If the call is the last action, you don&#39;t need to &amp;quot;remember&amp;quot; anything. You don&#39;t need a bookmark. You can just close the current book and move to the next one.&lt;/p&gt;
&lt;h3 id=&quot;converting-to-tail-recursion&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/csharp-recursion/#converting-to-tail-recursion&quot;&gt;&lt;span&gt;Converting to Tail Recursion&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;To make the Factorial function tail-recursive, we need to pass the &amp;quot;answer so far&amp;quot; (accumulator) into the next step, so we have nothing left to do after the call returns.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// TAIL RECURSIVE (Conceptually)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;FactorialTail&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; n&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; accumulator &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;n &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; accumulator&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;// The recursive call is the ONLY thing happening at the end.&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// We don&#39;t need to remember &#39;n&#39; here, it&#39;s already used in the calculation.&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;FactorialTail&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;n &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; n &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; accumulator&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In languages like F# or C++, the compiler sees this and says: &amp;quot;Aha! You don&#39;t need to come back here. I will just replace the current stack frame with the new one.&amp;quot; This effectively turns your recursion into a &lt;code&gt;while&lt;/code&gt; loop behind the scenes. Zero memory growth.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt; The C# compiler (Roslyn) does not guarantee this optimization. Even if you write perfect tail-recursive code, C# will often still add stack frames, and you will still crash.&lt;/p&gt;
&lt;h2 id=&quot;part-3:-the-&amp;quot;clever&amp;quot;-solution-(the-trampoline)&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/csharp-recursion/#part-3:-the-%22clever%22-solution-(the-trampoline)&quot;&gt;&lt;span&gt;Part 3: The &amp;quot;Clever&amp;quot; Solution (The Trampoline)&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Since C# won&#39;t optimize the stack for us, we can do it ourselves using a design pattern called a &lt;strong&gt;Trampoline&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;A Trampoline is a loop that runs functions. Instead of function A calling function B directly (and growing the stack), function A returns an &lt;strong&gt;instruction&lt;/strong&gt; to call function B. The Trampoline catches that instruction and runs B.&lt;/p&gt;
&lt;p&gt;Imagine a manager (the Trampoline) and a worker (your recursive function):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Manager:&lt;/strong&gt; &amp;quot;Do the work.&amp;quot;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Worker:&lt;/strong&gt; &amp;quot;I did a bit of work, but I need to do more with these new inputs. Here is the request.&amp;quot;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Manager:&lt;/strong&gt; &amp;quot;Okay, I&#39;ll restart you with those inputs.&amp;quot;&lt;br /&gt;
(The stack never grows because the worker returns to the manager every time.)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;a-simple-implementation&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/csharp-recursion/#a-simple-implementation&quot;&gt;&lt;span&gt;A Simple Implementation&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;We need a wrapper class to represent the &amp;quot;next step.&amp;quot;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Trampoline&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Executes the recursive logic in a loop&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;token generic-method&quot;&gt;&lt;span class=&quot;token function&quot;&gt;Execute&lt;/span&gt;&lt;span class=&quot;token generic class-name&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;T&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Func&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;Bounce&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;T&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; func&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt;&lt;/span&gt; result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;func&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;IsFinished&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; result&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; result&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;NextStep&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// &quot;Bounce&quot; to the next step&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Represents the state: either we are done, or we have more work&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Bounce&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;T&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;T&lt;/span&gt; Value &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;Func&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;Bounce&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;T&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; NextStep &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;bool&lt;/span&gt;&lt;/span&gt; IsFinished &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Bounce&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Func&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;Bounce&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;T&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; nextStep&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;bool&lt;/span&gt;&lt;/span&gt; isFinished&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        Value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        NextStep &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; nextStep&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        IsFinished &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; isFinished&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;// Helper: We are done!&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;Bounce&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;T&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;T&lt;/span&gt; result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;Bounce&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;T&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;// Helper: Keep going!&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;Bounce&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;T&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Recurse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Func&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;Bounce&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;T&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; next&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;Bounce&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;T&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; next&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;using-the-trampoline-(real-world-example)&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/csharp-recursion/#using-the-trampoline-(real-world-example)&quot;&gt;&lt;span&gt;Using the Trampoline (Real World Example)&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Let&#39;s use a real-world scenario. Imagine you are traversing a massive organizational hierarchy (a tree structure) to find a specific employee ID. A standard recursive search might crash if the organization is too deep.&lt;/p&gt;
&lt;p&gt;Here is how we use the Trampoline to make it safe:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;OrgSearch&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;Bounce&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;FindEmployee&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; currentId&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; targetId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// 1. Base Case: Found it&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;currentId &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; targetId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; Bounce&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;$&quot;Found employee &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token expression language-csharp&quot;&gt;currentId&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;!&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token comment&quot;&gt;// 2. Base Case: Dead end (mock logic)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;currentId &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;100000&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; Bounce&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Not found.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token comment&quot;&gt;// 3. Recursive Step: Return a function that says &quot;Check the next ID&quot;&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// Notice we utilize a lambda () =&gt; ... to delay execution&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; Bounce&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Recurse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;FindEmployee&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;currentId &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; targetId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Usage&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Program&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// This would normally crash a stack, but here it runs safely in a loop&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// because the &quot;recursion&quot; happens inside the Trampoline&#39;s while loop.&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Trampoline&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Execute&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; OrgSearch&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;FindEmployee&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;50000&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;result&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;summary&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/csharp-recursion/#summary&quot;&gt;&lt;span&gt;Summary&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Recursion&lt;/strong&gt; puts &amp;quot;bookmarks&amp;quot; on the stack. Too many bookmarks = Crash.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tail Recursion&lt;/strong&gt; is designing your function so no bookmark is needed (the recursive call is the last step).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;C# Limitations:&lt;/strong&gt; C# generally doesn&#39;t auto-optimize tail recursion.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Fix:&lt;/strong&gt; Use the &lt;strong&gt;Trampoline Pattern&lt;/strong&gt;. Instead of calling yourself deeply, return a &amp;quot;function&amp;quot; that the main loop executes. This turns recursion into iteration, keeping your memory usage flat.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Pro Tip:&lt;/strong&gt; If you are a beginner in C#, the easiest optimization is often to just rewrite the logic using a &lt;code&gt;while&lt;/code&gt; or &lt;code&gt;foreach&lt;/code&gt; loop. But understanding the Trampoline pattern opens your mind to how functional programming works and how to manage complex state changes without mutable variables.&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>Visualizing SonarCloud Metrics with Python - Build a Custom Dashboard for Your Code Quality.</title>
		<link href="https://bytedocs.vercel.app/posts/sonarclouddash/"/>
		<published>2025-07-03T00:00:00Z</published>
				<updated>2025-07-03T00:00:00Z</updated>
		<id>https://bytedocs.vercel.app/posts/sonarclouddash/</id>
		<content type="html">&lt;h2 id=&quot;introduction&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#introduction&quot;&gt;&lt;span&gt;Introduction&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;In today’s fast-moving software development landscape, tracking code quality isn’t just a nice-to-have—it’s essential. Tools like &lt;strong&gt;SonarCloud&lt;/strong&gt; have become ubiquitous in CI/CD pipelines, providing rich insights into code coverage, technical debt, bugs, and security vulnerabilities. But while SonarCloud’s own dashboards are great, sometimes you need &lt;strong&gt;custom analytics, visualizations tailored for your team, or integrations with your existing reporting workflows&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;That’s why I built the &lt;strong&gt;SonarCloud Metrics Dashboard&lt;/strong&gt;: an open-source, Python-based tool that fetches metrics from the SonarCloud API, stores them in Azure Table Storage for fast access and historical analysis, and visualizes them with an interactive dashboard built in Streamlit.&lt;/p&gt;
&lt;p&gt;In this article, I’ll show you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Why and how to fetch SonarCloud metrics programmatically&lt;/li&gt;
&lt;li&gt;How to design a user-friendly dashboard in Python&lt;/li&gt;
&lt;li&gt;How to persist and analyze historical code quality trends&lt;/li&gt;
&lt;li&gt;How to share your tool with your team—or the open-source community&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let’s dive in!&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;why-build-your-own-sonarcloud-dashboard&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#why-build-your-own-sonarcloud-dashboard&quot;&gt;&lt;span&gt;Why Build Your Own SonarCloud Dashboard?&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;SonarCloud provides a powerful UI, but as your organization grows, you might face challenges like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Needing &lt;strong&gt;custom charts or metric combinations&lt;/strong&gt; beyond what the web UI provides&lt;/li&gt;
&lt;li&gt;Wanting to &lt;strong&gt;track trends over time&lt;/strong&gt; for KPIs across multiple repositories or branches&lt;/li&gt;
&lt;li&gt;Integrating code quality data into &lt;strong&gt;automated reporting, business dashboards, or even team retrospectives&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Building your own dashboard means:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Full control over the data, timeframes, and metrics you care about&lt;/li&gt;
&lt;li&gt;Ability to combine SonarCloud data with other sources (test coverage, deployment metrics, etc.)&lt;/li&gt;
&lt;li&gt;A great excuse to learn Streamlit and modern data visualization in Python&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;overview:-sonarcloud-metrics-dashboard&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#overview:-sonarcloud-metrics-dashboard&quot;&gt;&lt;span&gt;Overview: SonarCloud Metrics Dashboard&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Features:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Interactive dashboards:&lt;/strong&gt; View key metrics (coverage, bugs, vulnerabilities, code smells, etc.) for any project and branch&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Historical trends:&lt;/strong&gt; Track changes over days, months, or a full year&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Azure Table Storage integration:&lt;/strong&gt; Persist data for offline access and fast reloads&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Customizable metrics and visualizations:&lt;/strong&gt; Choose what matters to your team&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Open source and ready for you to extend&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/FmoOliveira/SonarCloudDashboard&quot;&gt;GitHub Repo&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;architecture&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#architecture&quot;&gt;&lt;span&gt;Architecture&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Here’s how the main components fit together:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Streamlit Frontend:&lt;/strong&gt; Interactive web UI for metric selection, filtering, and visualization&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SonarCloud API Client:&lt;/strong&gt; Handles authentication and metric fetching&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Azure Table Storage:&lt;/strong&gt; Stores metric snapshots for historical analysis and caching&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Visualization Components:&lt;/strong&gt; Trend lines, bar charts, box plots, and metric cards (built with Plotly)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here’s a simplified diagram:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre tabindex=&quot;0&quot;&gt;&lt;code&gt;[SonarCloud API] &amp;lt;---&amp;gt; [Python API Client] &amp;lt;---&amp;gt; [Azure Table Storage]
        |                           |
    (live metrics)          (historical cache)
        |                           |
            [Streamlit Dashboard UI]
                    |
            [User: Selects Org/Project/Branch, Visualizes, Exports]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;implementation:-step-by-step&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#implementation:-step-by-step&quot;&gt;&lt;span&gt;Implementation: Step by Step&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;h3 id=&quot;1.-prerequisites&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#1.-prerequisites&quot;&gt;&lt;span&gt;1. Prerequisites&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Python 3.8+&lt;/li&gt;
&lt;li&gt;SonarCloud account (and an &lt;a href=&quot;https://sonarcloud.io/account/security/&quot;&gt;API token&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Azure account (for Table Storage, optional but recommended)&lt;/li&gt;
&lt;li&gt;Basic knowledge of Python and working with virtual environments&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;2.-clone-and-install&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#2.-clone-and-install&quot;&gt;&lt;span&gt;2. Clone and Install&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-bash&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;git&lt;/span&gt; clone https://github.com/FmoOliveira/SonarCloudDashboard.git
&lt;span class=&quot;token builtin class-name&quot;&gt;cd&lt;/span&gt; sonarcloud-metrics-dashboard
pip &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;token parameter variable&quot;&gt;-r&lt;/span&gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;3.-configuration&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#3.-configuration&quot;&gt;&lt;span&gt;3. Configuration&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Create a &lt;code&gt;.env&lt;/code&gt; file in the project root:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-bash&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token assign-left variable&quot;&gt;SONARCLOUD_TOKEN&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;your_sonarcloud_token
&lt;span class=&quot;token assign-left variable&quot;&gt;SONARCLOUD_ORG&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;your_sonarcloud_organization_key
&lt;span class=&quot;token assign-left variable&quot;&gt;AZURE_STORAGE_CONNECTION_STRING&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;your_azure_storage_connection_string
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;4.-how-the-core-logic-works&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#4.-how-the-core-logic-works&quot;&gt;&lt;span&gt;4. How the Core Logic Works&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;h4 id=&quot;a)-fetching-projects-and-metrics&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#a)-fetching-projects-and-metrics&quot;&gt;&lt;span&gt;a) Fetching Projects and Metrics&lt;/span&gt;&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;The &lt;code&gt;SonarCloudAPI&lt;/code&gt; class in &lt;code&gt;sonarcloud_api.py&lt;/code&gt; wraps API calls:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-python&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;SonarCloudAPI&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;__init__&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;self&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; token&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        self&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;token &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; token
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;get_organization_projects&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;self&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; organization&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; List&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;Dict&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;get_project_measures&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;self&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; project_key&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; branch&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; Optional&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;Dict&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;get_project_history&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;self&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; project_key&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; days&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; branch&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; List&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;Dict&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Get all projects in your organization&lt;/li&gt;
&lt;li&gt;For a given project/branch, fetch live or historical metrics (coverage, bugs, etc.)&lt;/li&gt;
&lt;li&gt;Handles API auth and error cases&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;b)-storing-metrics-for-historical-analysis&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#b)-storing-metrics-for-historical-analysis&quot;&gt;&lt;span&gt;b) Storing Metrics for Historical Analysis&lt;/span&gt;&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;azure_storage.py&lt;/code&gt; uses Azure Table Storage to cache metrics. This allows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Super-fast reloads&lt;/li&gt;
&lt;li&gt;The ability to analyze trends even if SonarCloud rate-limits your API access&lt;/li&gt;
&lt;li&gt;Easy export of all your historical data as CSV&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;c)-visualization-and-dashboard&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#c)-visualization-and-dashboard&quot;&gt;&lt;span&gt;c) Visualization and Dashboard&lt;/span&gt;&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;app.py&lt;/code&gt; is your Streamlit entry point:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Sidebar controls:&lt;/strong&gt; Select organization, project, branch, date range, and which metrics to display&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Main area:&lt;/strong&gt; Metric cards (summary), trend charts, comparison charts, data tables, export buttons&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interactivity:&lt;/strong&gt; The dashboard updates only when you request it—so you can experiment with filters and metric combinations without unnecessary API calls&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example: Displaying a trend line for “coverage” metric over 30 days:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-python&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-python&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;create_trend_chart&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;df&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; pd&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;DataFrame&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; metric&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; project_names&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;dict&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
    fig &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; px&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;line&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
        plot_data&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        x&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;date&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        y&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;metric&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        color&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;project_name&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        title&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token string-interpolation&quot;&gt;&lt;span class=&quot;token string&quot;&gt;f&quot;&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;metric&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;replace&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&#39;_&#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#39; &#39;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;title&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt; Trend Over Time&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
        markers&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;True&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    st&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;plotly_chart&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;fig&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; use_container_width&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token boolean&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h4 id=&quot;d)-exporting-your-data&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#d)-exporting-your-data&quot;&gt;&lt;span&gt;d) Exporting Your Data&lt;/span&gt;&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;The dashboard includes a download button to export the currently filtered dataset as CSV—ready for further analysis or sharing with your team.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;running-the-dashboard&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#running-the-dashboard&quot;&gt;&lt;span&gt;Running the Dashboard&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Start the Streamlit app:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-bash&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;streamlit run app.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Visit the local address provided in the terminal—typically &lt;a href=&quot;http://localhost:8501/&quot;&gt;http://localhost:8501&lt;/a&gt;.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;customizing-and-extending&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#customizing-and-extending&quot;&gt;&lt;span&gt;Customizing and Extending&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Want different charts? Extend &lt;code&gt;dashboard_components.py&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Need additional metrics? Update the metric lists in the API and storage classes.&lt;/li&gt;
&lt;li&gt;Want to support other backends (e.g., local SQLite, Google Sheets)? Just add a storage module.&lt;/li&gt;
&lt;li&gt;Fancy running this in Docker or deploying to Azure Web Apps? Easy—Streamlit supports containerization and cloud deployment.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;try-it-yourself!&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#try-it-yourself!&quot;&gt;&lt;span&gt;Try It Yourself!&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;This project is licensed under the MIT License — use it, fork it, open issues or PRs. All contributions are welcome! See the repo on &lt;a href=&quot;https://github.com/FmoOliveira/SonarCloudDashboard&quot;&gt;GitHub&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Clone the repo, set your credentials, and visualize your own organization’s code quality!&lt;/li&gt;
&lt;li&gt;Want to integrate this with Slack, Teams, or email digests? The modular design makes that a straightforward extension.&lt;/li&gt;
&lt;li&gt;Got feedback or feature ideas? &lt;a href=&quot;https://github.com/FmoOliveira/SonarCloudDashboard/issues&quot;&gt;Open an issue on GitHub!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;final-thoughts&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/sonarclouddash/#final-thoughts&quot;&gt;&lt;span&gt;Final Thoughts&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;This project was first and foremost a learning journey—a way for me to get hands-on with Streamlit, explore its rapid dashboarding capabilities, and see just how easily I could visualize real-world DevOps metrics. Building this SonarCloud dashboard was fun, experimental, and driven by curiosity rather than enterprise requirements.&lt;/p&gt;
&lt;p&gt;If you’re considering using this in a production environment, please keep in mind:&lt;br /&gt;
This tool was built for fun and learning, not as a ready-made enterprise product. While it’s open-source and flexible, you should review, adapt, and test it thoroughly for your own use case before relying on it for critical reporting or team dashboards.&lt;/p&gt;
&lt;p&gt;That said, I hope you find it inspiring—whether you want to tinker, learn Streamlit, or spin up a dashboard for your own data.&lt;br /&gt;
If you have suggestions, ideas, or want to improve it, I welcome your feedback and contributions!&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;&lt;strong&gt;Tags:&lt;/strong&gt;&lt;br /&gt;
#Python #DevOps #SonarCloud #CodeQuality #Streamlit #OpenSource #Azure #Dashboard #SoftwareEngineering&lt;/p&gt;
</content>
	</entry>
	
	<entry>
		<title>C# Flow Control</title>
		<link href="https://bytedocs.vercel.app/posts/firstpost/"/>
		<published>2025-01-01T00:00:00Z</published>
				<updated>2025-01-01T00:00:00Z</updated>
		<id>https://bytedocs.vercel.app/posts/firstpost/</id>
		<content type="html">&lt;p&gt;In this article, we&#39;ll explore flow control in csharp, a fundamental topic for any software developer. Effective management of flow control ensures that your program behaves predictably, performs efficiently, and remains readable and maintainable. Based on industry best practices, including insights from Steve McConnell&#39;s &lt;em&gt;Code Complete&lt;/em&gt;, we&#39;ll delve into key flow control structures like &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;switch&lt;/code&gt;, loops (&lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;do-while&lt;/code&gt;, &lt;code&gt;foreach&lt;/code&gt;), and the &lt;code&gt;break&lt;/code&gt;/&lt;code&gt;continue&lt;/code&gt; statements.&lt;/p&gt;
&lt;h2 id=&quot;the-if-statement&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#the-if-statement&quot;&gt;&lt;span&gt;The &lt;code&gt;if&lt;/code&gt; Statement&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;if&lt;/code&gt; statement is a fundamental control structure that evaluates a Boolean condition and executes a block of code if the condition is &lt;code&gt;true&lt;/code&gt;. Writing effective &lt;code&gt;if&lt;/code&gt; statements is crucial for maintaining clean, readable, and efficient code.&lt;/p&gt;
&lt;h3 id=&quot;example:&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#example:&quot;&gt;&lt;span&gt;Example:&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; threshold &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; userInput &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;25&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; 

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;userInput &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; threshold&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;The input matches the threshold! 🥳&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;best-practices&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#best-practices&quot;&gt;&lt;span&gt;Best Practices&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Use Clear Conditions&lt;/strong&gt;&lt;br /&gt;
The condition inside an &lt;code&gt;if&lt;/code&gt; statement should be simple and easy to understand. Avoid writing complex or convoluted expressions that make the logic hard to follow. If necessary, break the condition into smaller, meaningful variables or expressions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Before:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Complex logic...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;After:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;bool&lt;/span&gt;&lt;/span&gt; isInValidRange &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;bool&lt;/span&gt;&lt;/span&gt; isOutOfRange &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;isInValidRange &lt;span class=&quot;token operator&quot;&gt;||&lt;/span&gt; isOutOfRange&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Clearer logic...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Avoid Nested &lt;code&gt;if&lt;/code&gt; Statements&lt;/strong&gt;&lt;br /&gt;
While nesting &lt;code&gt;if&lt;/code&gt; statements can sometimes be necessary, excessive nesting makes the code hard to follow. Instead of deeply nested &lt;code&gt;if&lt;/code&gt; blocks, consider &lt;strong&gt;guard clauses&lt;/strong&gt;—an early return or exit strategy that reduces nesting, which make your code flatter and easier to read.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Before:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;IsActive&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;HasPermissions&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token comment&quot;&gt;// Perform action...&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;After (Using Guard Clauses):&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;IsActive&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;HasPermissions&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// Perform action...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Favor Positive Conditions&lt;/strong&gt;&lt;br /&gt;
Whenever possible, write conditions in a positive manner. Positive conditions are easier to understand and often make your code more readable. For example, instead of negating a condition, use its positive equivalent.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Before (Negative Condition):&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;isInvalid&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Logic for valid case...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;After (Positive Condition):&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;isValid&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Logic for valid case...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Handle Edge Cases and Errors First (Guard Clauses)&lt;/strong&gt;&lt;br /&gt;
Guard clauses allow you to handle edge cases and errors early in your code, preventing unnecessary complexity. By handling invalid conditions upfront, the main logic becomes more readable and manageable.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;customer &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token constructor-invocation class-name&quot;&gt;ArgumentNullException&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;nameof&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;customer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;customer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;IsActive&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Customer account is inactive.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// Continue with core logic for active customers...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Put the Normal Case First&lt;/strong&gt;&lt;br /&gt;
As Steve McConnell suggests in &lt;em&gt;Code Complete&lt;/em&gt;, always handle the normal or expected case first in an &lt;code&gt;if&lt;/code&gt; block. This keeps the focus on the main flow of logic, while exceptional cases can be handled afterward. This makes the code easier to follow.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Before:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;isAuthorized&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Handle unauthorized case...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Main logic for authorized case...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;After (Normal Case First):&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;isAuthorized&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Main logic for authorized case...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Handle unauthorized case...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Consider using &lt;code&gt;switch&lt;/code&gt; for multiple conditions&lt;/strong&gt;&lt;br /&gt;
When dealing with multiple conditions related to a single variable, a &lt;code&gt;switch&lt;/code&gt; statement is often more readable than a series of &lt;code&gt;if-else&lt;/code&gt; blocks. It provides a structured way to handle multiple cases, making it easier to see all the conditions at a glance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Before (Multiple &lt;code&gt;if&lt;/code&gt; Statements):&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;status &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Pending&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Handle pending status...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;status &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Approved&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Handle approved status...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;status &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Rejected&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Handle rejected status...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;After (&lt;code&gt;switch&lt;/code&gt; Statement):&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;status&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Pending&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// Handle pending status...&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Approved&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// Handle approved status...&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Rejected&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// Handle rejected status...&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// Handle unknown status...&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Refactor Complex &lt;code&gt;if&lt;/code&gt; Logic&lt;/strong&gt;&lt;br /&gt;
If your &lt;code&gt;if&lt;/code&gt; conditions become too complex, it&#39;s a sign that you should refactor the code. Extracting logic into separate methods or using design patterns (like the &lt;strong&gt;Strategy Pattern&lt;/strong&gt;) can simplify decision-making and improve code readability.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ShouldSendNotification&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; notificationType&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;SendNotification&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; notificationType&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Test and Document Your Conditions&lt;/strong&gt;&lt;br /&gt;
Always ensure that your conditions are thoroughly tested, including edge cases, null checks, and unexpected inputs. Use comments to document complex conditions or edge cases, making your code easier to maintain.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// Ensure the user is not null and has the necessary permissions&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;user &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; user&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;HasPermissions&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// Perform action...&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;the-switch-statement&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#the-switch-statement&quot;&gt;&lt;span&gt;The &lt;code&gt;switch&lt;/code&gt; Statement&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;switch&lt;/code&gt; statement is a control structure used to select one of many code blocks to execute based on the value of a variable. It&#39;s particularly useful when you need to compare a variable against several discrete values.&lt;/p&gt;
&lt;h3 id=&quot;example:-1&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#example:-1&quot;&gt;&lt;span&gt;Example:&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; status &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Approved&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;status&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Pending&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;The request is pending.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Approved&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;The request is approved.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Rejected&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;The request is rejected.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
        Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Unknown status.&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In this example, the program evaluates the value of &lt;code&gt;status&lt;/code&gt; and executes the corresponding block of code. If none of the cases match, the &lt;code&gt;default&lt;/code&gt; block is executed.&lt;/p&gt;
&lt;p&gt;In recent versions of csharp (beginning with csharp 8.0), the &lt;code&gt;switch&lt;/code&gt; statement has undergone significant enhancements through the integration of pattern matching. These improvements allow developers to write more concise and expressive code by leveraging &lt;strong&gt;&lt;code&gt;switch&lt;/code&gt; expressions&lt;/strong&gt;. This advancement simplifies the handling of multiple conditions and complex pattern matching scenarios, often reducing the verbosity commonly associated with traditional &lt;code&gt;switch&lt;/code&gt; statements.&lt;/p&gt;
&lt;p&gt;The introduction of &lt;strong&gt;&lt;code&gt;switch&lt;/code&gt; expressions&lt;/strong&gt; not only shortens the code but also enhances its readability and maintainability, making it a powerful tool for developers working with conditional logic.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;GetDayName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; day&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; day &lt;span class=&quot;token keyword&quot;&gt;switch&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Monday&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Tuesday&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Wednesday&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    _ &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Unknown&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;pattern-matching-with-switch-expressions&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#pattern-matching-with-switch-expressions&quot;&gt;&lt;span&gt;Pattern Matching with &lt;code&gt;switch&lt;/code&gt; Expressions&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;switch&lt;/code&gt; expressions become even more powerful with pattern matching, allowing for checks beyond simple equality, such as type checks and property matches. For example:&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;DescribeNumber&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt;&lt;/span&gt; number&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; number &lt;span class=&quot;token keyword&quot;&gt;switch&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; n &lt;span class=&quot;token keyword&quot;&gt;when&lt;/span&gt; n &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Positive integer&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; n &lt;span class=&quot;token keyword&quot;&gt;when&lt;/span&gt; n &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Negative integer&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;double&lt;/span&gt;&lt;/span&gt; d &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Double&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;No value&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    _ &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Unknown type&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This example uses &lt;strong&gt;relational patterns&lt;/strong&gt; and &lt;strong&gt;type patterns&lt;/strong&gt; to match different types of numbers and handle them accordingly.&lt;/p&gt;
&lt;h3 id=&quot;advanced-pattern-matching:&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#advanced-pattern-matching:&quot;&gt;&lt;span&gt;Advanced Pattern Matching:&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Relational Patterns&lt;/strong&gt;: You can check ranges of values using conditions like &lt;code&gt;&amp;lt;&lt;/code&gt; and &lt;code&gt;&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;WaterState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; temperature&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; temperature &lt;span class=&quot;token keyword&quot;&gt;switch&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;32&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Solid&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;212&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Gas&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    _ &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Liquid&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Property Patterns&lt;/strong&gt;: These allow matching based on object properties.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;record&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Person&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; Name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; Age&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CheckPerson&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Person&lt;/span&gt; person&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; person &lt;span class=&quot;token keyword&quot;&gt;switch&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Age&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;18&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Adult&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; Age&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;18&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Minor&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    _ &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Unknown&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Tuple Patterns&lt;/strong&gt;: Useful when working with multiple values.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token return-type class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;ClassifyCoordinates&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; x&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;switch&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Origin&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;_&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;On the X axis&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; _&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;On the Y axis&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    _ &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Somewhere in the plane&quot;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;best-practices-for-switch-statements:&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#best-practices-for-switch-statements:&quot;&gt;&lt;span&gt;Best Practices for &lt;code&gt;switch&lt;/code&gt; Statements:&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Always Include a &lt;code&gt;default&lt;/code&gt; Case&lt;/strong&gt;: A &lt;code&gt;default&lt;/code&gt; case ensures that your program handles unexpected or unhandled values gracefully.&lt;br /&gt;
&lt;strong&gt;Keep Cases Short and Concise&lt;/strong&gt;: Each case in a &lt;code&gt;switch&lt;/code&gt; should perform a specific task. If the logic is complex, consider refactoring it into a separate method to keep the &lt;code&gt;switch&lt;/code&gt; statement readable.&lt;br /&gt;
&lt;strong&gt;Use Pattern Matching&lt;/strong&gt;: Leverage csharp 8.0+ features for more expressive code.&lt;/p&gt;
&lt;h2 id=&quot;loops-in-csharp&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#loops-in-csharp&quot;&gt;&lt;span&gt;Loops in csharp&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;csharp provides four primary looping structures: &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt;, &lt;code&gt;do-while&lt;/code&gt;, and &lt;code&gt;foreach&lt;/code&gt;. Each has its specific use cases and best practices.&lt;/p&gt;
&lt;h3 id=&quot;the-for-loop&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#the-for-loop&quot;&gt;&lt;span&gt;The &lt;code&gt;for&lt;/code&gt; Loop&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;for&lt;/code&gt; loop repeats a block of code a specific number of times, which makes it ideal for iterating over arrays or performing a task a known number of times.&lt;/p&gt;
&lt;h3 id=&quot;example:-2&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#example:-2&quot;&gt;&lt;span&gt;Example:&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;$&quot;Iteration &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token expression language-csharp&quot;&gt;i &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;best-practices-for-for-loops:&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#best-practices-for-for-loops:&quot;&gt;&lt;span&gt;Best Practices for &lt;code&gt;for&lt;/code&gt; Loops:&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Use Descriptive Variable Names&lt;/strong&gt;: Instead of &lt;code&gt;i&lt;/code&gt;, use meaningful variable names if the context requires it (e.g., &lt;code&gt;index&lt;/code&gt; or &lt;code&gt;counter&lt;/code&gt;), especially in nested loops.&lt;br /&gt;
&lt;strong&gt;Avoid Magic Numbers&lt;/strong&gt;: Rather than hardcoding values like &lt;code&gt;5&lt;/code&gt; directly in the condition, use a named constant or variable to improve readability.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; numberOfIterations &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; index &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; index &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; numberOfIterations&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; index&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;$&quot;Iteration &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token expression language-csharp&quot;&gt;index &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;the-while-loop&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#the-while-loop&quot;&gt;&lt;span&gt;The &lt;code&gt;while&lt;/code&gt; Loop&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;while&lt;/code&gt; loop is particularly useful when you do not know the number of iterations in advance because it continues to execute as long as its condition remains true. This makes it ideal for scenarios where the termination condition is not based on a predefined number of iterations, but rather on a dynamic or external condition being met during execution.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; counter &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;counter &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;$&quot;Counter: &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token expression language-csharp&quot;&gt;counter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    counter&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;best-practices-for-while-loops:&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#best-practices-for-while-loops:&quot;&gt;&lt;span&gt;Best Practices for &lt;code&gt;while&lt;/code&gt; Loops:&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Ensure Your Loop Will Eventually Terminate&lt;/strong&gt;: Always update variables inside the loop to ensure the condition will eventually become &lt;code&gt;false&lt;/code&gt;, avoiding infinite loops.&lt;br /&gt;
&lt;strong&gt;Consider Loop Conditions Carefully&lt;/strong&gt;: If the condition may never be met or is complex, consider adding a safety mechanism or logging to debug the loop&#39;s behavior.&lt;/p&gt;
&lt;h3 id=&quot;the-do-while-loop&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#the-do-while-loop&quot;&gt;&lt;span&gt;The &lt;code&gt;do-while&lt;/code&gt; Loop&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;A &lt;code&gt;do-while&lt;/code&gt; loop is similar to a &lt;code&gt;while&lt;/code&gt; loop, but it guarantees that the code inside the loop will run at least once, even if the condition is &lt;code&gt;false&lt;/code&gt; initially.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; userInput&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Enter a number greater than 10: &quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    userInput &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ReadLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;userInput &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;$&quot;You entered: &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token expression language-csharp&quot;&gt;userInput&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;best-practices-for-do-while-loops:&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#best-practices-for-do-while-loops:&quot;&gt;&lt;span&gt;Best Practices for &lt;code&gt;do-while&lt;/code&gt; Loops:&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Use When You Want at Least One Execution&lt;/strong&gt;: The primary use case for a &lt;code&gt;do-while&lt;/code&gt; loop is when you need the loop to execute at least once, even if the condition is not met from the start.&lt;/p&gt;
&lt;h3 id=&quot;the-foreach-loop&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#the-foreach-loop&quot;&gt;&lt;span&gt;The &lt;code&gt;foreach&lt;/code&gt; Loop&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;foreach&lt;/code&gt; loop is a more convenient way to iterate over collections, such as arrays, lists, or dictionaries. It automatically iterates through each element in the collection.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/span&gt; fruits &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Apple&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Banana&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Cherry&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;/span&gt; fruit &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; fruits&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;fruit&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;best-practices-for-foreach-loops:&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#best-practices-for-foreach-loops:&quot;&gt;&lt;span&gt;Best Practices for &lt;code&gt;foreach&lt;/code&gt; Loops:&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Use When Iterating Over Collections&lt;/strong&gt;: A &lt;code&gt;foreach&lt;/code&gt; loop is simpler and more readable than a &lt;code&gt;for&lt;/code&gt; loop when iterating over collections because you don&#39;t need to manage index values manually.&lt;br /&gt;
&lt;strong&gt;Avoid Modifying Collections Inside a &lt;code&gt;foreach&lt;/code&gt;&lt;/strong&gt;: Modifying the collection (e.g., adding or removing elements) during iteration can lead to runtime exceptions. If you need to modify the collection, consider using a &lt;code&gt;for&lt;/code&gt; loop or iterating over a copy of the collection.&lt;/p&gt;
&lt;h2 id=&quot;the-break-and-continue-statements&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#the-break-and-continue-statements&quot;&gt;&lt;span&gt;The &lt;code&gt;break&lt;/code&gt; and &lt;code&gt;continue&lt;/code&gt; Statements&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;csharp&#39;s &lt;code&gt;break&lt;/code&gt; and &lt;code&gt;continue&lt;/code&gt; statements offer precise control over loops and switch statements. &lt;code&gt;break&lt;/code&gt; exits a loop or switch case early, while &lt;code&gt;continue&lt;/code&gt; skips to the next iteration. These tools, when used judiciously, can significantly enhance code efficiency and readability.&lt;/p&gt;
&lt;h3 id=&quot;the-break-statement&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#the-break-statement&quot;&gt;&lt;span&gt;The &lt;code&gt;break&lt;/code&gt; Statement&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;break&lt;/code&gt; statement is used to immediately exit the loop or &lt;code&gt;switch&lt;/code&gt; statement in which it is placed. When the &lt;code&gt;break&lt;/code&gt; statement is executed, control is transferred to the code following the loop or &lt;code&gt;switch&lt;/code&gt; block.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Exit the loop when i is 5&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;$&quot;Iteration &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token expression language-csharp&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;best-practices-for-using-break:&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#best-practices-for-using-break:&quot;&gt;&lt;span&gt;Best Practices for Using &lt;code&gt;break&lt;/code&gt;:&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Use &lt;code&gt;break&lt;/code&gt; to Exit Early from Loops When Necessary&lt;/strong&gt;: You can use &lt;code&gt;break&lt;/code&gt; to terminate loops early when a certain condition is met. This can improve performance if continuing the loop would be unnecessary.&lt;br /&gt;
&lt;strong&gt;Avoid Overusing &lt;code&gt;break&lt;/code&gt; in Complex Loops&lt;/strong&gt;: While &lt;code&gt;break&lt;/code&gt; can simplify loop logic, overusing it can make loops harder to understand. Use it sparingly and consider refactoring complex loops to improve readability.&lt;br /&gt;
&lt;strong&gt;Always Include &lt;code&gt;break&lt;/code&gt; in &lt;code&gt;switch&lt;/code&gt; Statements&lt;/strong&gt;: Ensure that each case in a &lt;code&gt;switch&lt;/code&gt; statement has a &lt;code&gt;break&lt;/code&gt; (or equivalent control flow like &lt;code&gt;return&lt;/code&gt; or &lt;code&gt;throw&lt;/code&gt;), unless you intend to let execution fall through to the next case.&lt;/p&gt;
&lt;h3 id=&quot;the-continue-statement&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#the-continue-statement&quot;&gt;&lt;span&gt;The &lt;code&gt;continue&lt;/code&gt; Statement&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;continue&lt;/code&gt; statement skips the remaining code inside the loop for the current iteration and proceeds to the next iteration. Unlike &lt;code&gt;break&lt;/code&gt;, &lt;code&gt;continue&lt;/code&gt; does not terminate the loop, it just skips to the next loop cycle.&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i &lt;span class=&quot;token operator&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;continue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Skip the rest of the loop body for even numbers&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token interpolation-string&quot;&gt;&lt;span class=&quot;token string&quot;&gt;$&quot;Odd number: &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token expression language-csharp&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&quot;best-practices-for-using-continue:&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#best-practices-for-using-continue:&quot;&gt;&lt;span&gt;Best Practices for Using &lt;code&gt;continue&lt;/code&gt;:&lt;/span&gt;&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Use &lt;code&gt;continue&lt;/code&gt; to Skip Unnecessary Processing&lt;/strong&gt;: When certain iterations in a loop don&#39;t require further processing, &lt;code&gt;continue&lt;/code&gt; can help you skip unnecessary steps, making the loop more efficient.&lt;br /&gt;
&lt;strong&gt;Avoid Overusing &lt;code&gt;continue&lt;/code&gt;&lt;/strong&gt;: While &lt;code&gt;continue&lt;/code&gt; can simplify loops, excessive use may make the loop logic harder to follow. Ensure that it is used only when necessary to improve clarity.&lt;br /&gt;
&lt;strong&gt;Prefer &lt;code&gt;continue&lt;/code&gt; Over Complex &lt;code&gt;if&lt;/code&gt; Logic&lt;/strong&gt;: In some cases, using &lt;code&gt;continue&lt;/code&gt; is clearer than adding multiple nested &lt;code&gt;if&lt;/code&gt; conditions. For example, instead of writing complex conditional logic inside a loop, you can use &lt;code&gt;continue&lt;/code&gt; to skip iterations early.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Before (Complex &lt;code&gt;if&lt;/code&gt; Condition):&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i &lt;span class=&quot;token operator&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// Perform action only for odd numbers&lt;/span&gt;
        Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;After (Using &lt;code&gt;continue&lt;/code&gt; for Clarity):&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;language-csharp&quot; tabindex=&quot;0&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i &lt;span class=&quot;token operator&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;continue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Skip even numbers&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    Console&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteLine&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;i&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Perform action only for odd numbers&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;conclusion&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#conclusion&quot;&gt;&lt;span&gt;Conclusion&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;Mastering flow control in csharp is vital to writing clean, maintainable, and efficient code. By following these best practices and leveraging modern csharp features, you can significantly improve your code quality and readability.&lt;/p&gt;
&lt;h2 id=&quot;references&quot; tabindex=&quot;-1&quot;&gt;&lt;a class=&quot;heading-link&quot; href=&quot;https://bytedocs.vercel.app/posts/firstpost/#references&quot;&gt;&lt;span&gt;References&lt;/span&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;McConnell, S. (2004). &lt;em&gt;Code Complete&lt;/em&gt; (2nd ed.). Microsoft Press.&lt;br /&gt;
Microsoft. (n.d.). &lt;em&gt;Pattern matching&lt;/em&gt;. Microsoft Learn. &lt;a href=&quot;https://learn.microsoft.com/en-us/dotnet//language-reference/operators/patterns&quot;&gt;https://learn.microsoft.com/en-us/dotnet//language-reference/operators/patterns&lt;/a&gt;&lt;/p&gt;
</content>
	</entry>
</feed>
