title: Why does this program return headNode at the end out of else block
body: <p><a href="https://i.stack.imgur.com/ymKkk.jpg" rel="nofollow noreferrer">Book picture 1</a>
  <a href="https://i.stack.imgur.com/Yqx6M.jpg" rel="nofollow noreferrer">Book picture</a></p>
  <p>I started with basic linkedlist operations.</p>
  <p>This is a program to insert a new node at the beginning or a specific position in linkedlist.</p>
  <p>I understand the first picture has the case where if linked list is empty insert return new node.</p>
  <ol>
  <li>If invalid position for insertion, return head.</li>
  <li>Last if else block, if position is at the beginning insert new node at the beginning, point next to head and return new node.</li>
  <li>I understand what else block is doing, inserting at a specific position.</li>
  </ol>
  <p>Question (I know it is dumb): why are we returning <code>headNode</code> at the end if we had returned a node in every case/block mentioned above?
  Should it not be returned inside the last else block but not outside?</p>