Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There seems to be a lot of confusion here over basic language structure and logic flow. Writing a few very simple test apps that exercise different language features will probably help you a lot. (So will a step-thru debugger, if you have one)</p> <p><code>do/while()</code> is a fairly advanced feature that some people spend whole careers never using, see: <a href="https://stackoverflow.com/questions/3347001/do-while-vs-while">do...while vs while</a></p> <p>I recommend getting a solid foundation with <code>while</code> and <code>if/else</code> before even using <code>for</code>. Your first look at <code>do</code> should be when you've just finished a <code>while</code> or <code>for</code> loop and realize you could save a mountain of duplicate initialization code if you just changed the order of execution a bit. (Personally I don't even use <code>do</code> for that any more, I just use an iterator with <code>while(true)/break</code> since it lets me pre <strong>and</strong> post code all within a single loop)</p> <p>I think this simplifies what you're trying to accomplish:</p> <pre><code>void Board::Loop(void) { //Display the postion of that Element. for (unsigned int i = 0; i &lt; 10; ++i) { while(IsGoingToCollide(i)) //check is first, do while doesn't make sense objects[i]-&gt;ResetPosition(); moveObject(i); //same as -&gt;SetPosition(XDir, YDir)? //either explain difference or remove one or the other } } </code></pre> <p>This function name seems ambiguous to me:</p> <pre><code>bool Board::checkCollisions(int index) { </code></pre> <p>I'd recommend changing it to:</p> <pre><code>// returns true if moving to next position (based on inertia) will // cause overlap with any other object's or structure's current location bool Board::IsGoingToCollide(int index) { </code></pre> <p>In contrast <code>checkCollisions()</code> could also mean: </p> <pre><code>// returns true if there is no overlap between this object's // current location and any other object's or structure's current location bool Board::DidntCollide(int index) { </code></pre> <p>Final note: Double check that <code>-&gt;ResetPosition()</code> puts things <strong>inside</strong> the boundaries.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload