title: How is local function in C#7.0 different from a foreach or a loop?
body: <p>This is more of a why question. Here it goes.</p>
  
  <p>C# 7.0 added a new feature called "Local Function". Below is a code snippet.</p>
  
  <pre><code>public int Fibonacci(int x)
  {
      if (x &lt; 0) throw new ArgumentException("Less negativity please!", nameof(x));
      return Fib(x).current;
  
      (int current, int previous) Fib(int i)
      {
          if (i == 0) return (1, 0);
          var (p, pp) = Fib(i - 1);
          return (p + pp, p);
      }
  }
  </code></pre>
  
  <p>What I dont understand is, its doing a recursive call to the same method. We can easily achieve this with a normal foreach. Then why a local function. </p>
  
  <p><a href="https://blogs.msdn.microsoft.com/dotnet/2017/03/09/new-features-in-c-7-0/" rel="nofollow noreferrer">MSDN</a> says </p>
  
  <blockquote>
    <p>methods implemented as iterators commonly need a non-iterator wrapper
    method for eagerly checking the arguments at the time of the call.
    (The iterator itself doesn’t start running until MoveNext is called).</p>
  </blockquote>
  
  <p>Need some help in understanding the concept that it. </p>