title: Breaking out of a loop from within a function called in that loop
body: <p>I'm currently trying to figure out a way to break out of a <code>for</code> loop from within a function called in that loop. I'm aware of the possibility to just have the function return a value and then check against a particular value and then break, but I'd like to do it from within the function directly.</p>
  
  <p>This is because I'm using an in-house library for a specific piece of hardware that mandates the function signature of my function to look like this:</p>
  
  <pre><code>void foo (int passV, int aVal, long bVal)
  </code></pre>
  
  <p>I'm aware that not using a return value is <strong>very bad practice</strong>, but alas circumstances force me to, so please bear with me.</p>
  
  <p>Consider following example:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void foo (int a) {
      printf("a: %d", a);
      break;
  }
  
  int main(void) {
      for (int i = 0; i &lt;= 100; i++) {
          foo(i);
      }
      return 0;
  }
  </code></pre>
  
  <p>Now this does not compile. Instead, I get a compilation error as follows:</p>
  
  <blockquote>
    <p>prog.c: In function 'foo': 
    prog.c:6:2: error: break statement not
    within loop or switch   break;</p>
  </blockquote>
  
  <p>I know what this means (the compiler says that the break in <code>foo()</code> is not within a <code>for</code> loop)</p>
  
  <p>Now, what I could find from the standard regarding the break statement is this:</p>
  
  <blockquote>
    <p>The break statement causes control to pass to the statement following
    the innermost enclosing while, do, for, or switch statement. The
    syntax is simply break;</p>
  </blockquote>
  
  <p>Considering my function is called from within a <code>for</code> loop, why doesn't the break statement break out of said for loop? Furthermore, is it possible to realise something like this without having the function return first?</p>