title: Exiting while(1) loop in C programming
body: <p>I am doing examples for my <code>C</code> programming class. And one of the examples is this:</p>
  
  <p>Update: Difference between <code>return 0;</code> and <code>break;</code></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main()
  {
  
  while(1)
  {
    printf("Enter number: ");
    scanf("%d", &amp;num);
  
    if (num==2)
     {
        return 0;
     }
    else
     {
        printf("Num = %d", num);
     }
  
  return 0;
  }
  </code></pre>
  
  <p>I know that <code>while(1)</code>is an infinite loop. 
  To get out of loop I used <code>break;</code>normally.</p>
  
  <p>But, in this example when <code>num=2</code> it gets out of loop.</p>
  
  <p>I don't understand how <code>return o;</code> effects the <code>while(1)</code> loop ?</p>