How to keep looping till a function returns?
<p>I am using a C++ graphics library which has functions <code>void WaitForMouseDown()</code> and <code>void WaitForMouseUp()</code>. The WaitForMouseDown function waits until the mouse button is pressed and then returns.  WaitForMouseUp waits for the button to be released.
There is another function in the library <code>bool isMouseDown()</code> which returns <code>true</code> if the mouse button is currently down.</p>

<p>Now, I have to start doing something in a loop when the user clicks the first time, and keep looping until user presses the mouse the second time.</p>

<p>I have tried the following approach, but for some reason the program crashes after the second click. Any ideas, what I am doing wrong?</p>

<pre><code>int main(){
   WaitForMouseUp();
   while(!isMouseDown()){
      //do something
   }
   return 0;
}
</code></pre>
