Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What's happening in the original:</p> <p>Javascript has <a href="http://en.wikipedia.org/wiki/For_loop#Kinds_of_for_loops" rel="nofollow">compound <em>for</em> loops</a>. The declaration inside the parenthesis has three expressions: <code>for(x; y; z){...}</code>.</p> <ul> <li><code>x</code> runs once before the loop</li> <li><code>y</code> is a condition, tested before each iteration. If it's false the loop will stop</li> <li><code>z</code> runs once after every iteration</li> </ul> <p>In this code, you set <code>j = world.m_jointList</code>, which is the first item in the linked list. The middle part of the <code>for</code> loop is checking for <a href="http://11heavens.com/falsy-and-truthy-in-javascript" rel="nofollow">thruthiness</a> of <code>j;</code>, and after each iteration <code>j</code> is set to <code>j.m_next</code>, which is a pointer to the next object in the chain. It ends when <code>j</code> evaluates to false (probably <code>undefined</code> in this case).</p> <p>To visualize that, <code>world</code> could look like this:</p> <pre><code>world = { m_jointList: { value: 'head', m_next: world.foo1 }, foo1: { value: 'foo', m_next: world.foo2 }, foo2: { value: 'foo', m_next: world.tail }, tail: { value: 'foo' } } </code></pre> <p>In reality the items in the list probably don't exist as properties of <code>world</code>, but this would work the same. Notice that <code>m_next</code> is undefined in the last object. Sometimes a placeholder value for the tail will be used indicating the end of the chain.</p> <p>The name <code>m_jointList</code> is also a bit misleading here because it doesn't actually contain the list, just the first element of it.</p> <p>This should do it in coffeescript:</p> <pre><code>j = world.m_jointList while j then drawJoint(j, context); j = j.m_next </code></pre> <p>And that would've been a good use of <code>do...while</code> in javascript:</p> <pre><code>var j = world.m_jointList do { drawJoint(j, context) } while (j = j.m_next) </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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