title: C++ Smallest common divisor rewrite
body: <p>I made a function that returns the smallest common divisor of 2 numbers. </p>
  
  <pre><code>int check (int a, int b)
  {
   int i = 2; //every number is divisible by 1
     begin:
      if ((a % i == 0) &amp;&amp; (b%i == 0)) //i must be divisible by both numbers
        {
           return i;
        }
      else
        {
            i++;
            goto begin;
        }
  }
  </code></pre>
  
  <p>However, I'm using the much-advised-against goto, so I was wondering how this could be rewritten using a <em>for</em> or <em>while</em> loop. </p>