Loop from x1,y1 to x2,y2, no matter in which order they are
<p>I want to be able to select part of an image via two Points (p1,p2). My problem is that I want to use the same loop regardless in which order they are.</p>

<p>right now I have this:</p>

<pre><code>for (int x = p1.X; x != p2.X; x += Math.Sign(p2.X - p1.X))
        {
            for (int y = p1.Y; y != p2.Y; y += Math.Sign(p2.Y - p1.Y))
            {
                MessageBox.Show(String.Format("{0} {1}", x, y));
            }
        }
</code></pre>

<p>With that loop I don't get all of the numbers:
e.g. from 1/1 to 3/3 only gones till 2/2.</p>

<p>I some how need to loop through both loops one more time, but since I don't know which way I'm actually looping (decreasing or increasing) I can't just add/ subtract one from the loop.</p>

<p>any help would be appreciated!</p>
