title: Clarification on while (true) loop with embedded If-Else
body: <p>I have been learning programming with C# and have come across a concept that I was not familiar with, that I am looking for clarification to help me better understand what is going on. This is not really specific to C#. It has to do with using a <code>while (true)</code> loop with an embedded <code>If-Else</code> statement.</p>
  <p>I was working through an example in a book and found that the author used <code>while (true)</code> loops inside of a method, which was called by the <code>Main</code> method. Within the author's <code>while</code> loop was an <code>If-Else</code> that contained the return value of the method.</p>
  <p>When I think of using <code>while (true)</code>, I think of an endless loop where you call break to get out of it. However, this loop did not need a break to get out. Rather it breaks if the condition of the <code>If</code> statement is true and loops if that condition is false. Below is an example.</p>
  <p>How is that the while loop breaks out when there is no variable condition for it to evaluate, rather it is hard-coded &quot;true&quot;? Does it have something to do with being inside a method and only breaks because the method is being called by the Main? Just looking to better understand this as it is a handy technique to use for validation.</p>
  <pre class="lang-cs prettyprint-override"><code>public void ValidateInteger()
  {
     while(true)
     {
        if (int.TryParse(Console.ReadLine(), out int value)
           return Console.WriteLine($&quot;{value} is an integer&quot;)
        else
           Console.WriteLine($&quot;{value} is not an integer, try again&quot;)
     }
  }
  </code></pre>