title: why does the statements inside loop condition execute when condition is false in c programming?
body: <p>I am just running a code to find the length of a given string input by the user in C programming language. I used a loop condition to determine the length but statements inside loop executes when the condition is false also. The code  I have tried in c is:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #define ArrayLength 50
  
  int StringLengthCount();
  
  int main() {
      printf(&quot;Hello, World!\n&quot;);
      
      /*Question: Find inserted string's length, without build in function*/
      int c=StringLengthCount();
      printf(&quot;Your inserted string's length is:%d&quot;,c);
  
  
      return 0;
  }
  
  int StringLengthCount(){
      
      printf(&quot;\n&quot;);
      printf(&quot;Please enter a sentence to find its length of character:&quot;);
      char array1[ArrayLength];
      fgets(array1,ArrayLength,stdin);
      printf(&quot;Your inserted string is:%s\n&quot;,array1);
  
      int i=0;
      int count=0;
      while(array1[i]!='\0'){
          count++;
          printf(&quot;%d character is %c&quot;,count,array1[i]);
          printf(&quot;\n&quot;);
          i++;
      }
  
      printf(&quot;\n&quot;);
      printf(&quot;Your inserted string's total character i.e string length is:%d&quot;,count);
  }
  </code></pre>
  <p>I am expecting the result 2 for a sample string input  &quot;we&quot;, but it gives result 3.
  The output result in CLion compiler is given below
  <a href="https://i.stack.imgur.com/agDJY.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>Can you kindly tell me why it happens?</p>