title: Porting duff's device from C to JavaScript
body: <p>I have this kind of Duff's device in C and it works fine (format text as money):</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  char *money(const char *src, char *dst)
  {
      const char *p = src;
      char *q = dst;
      size_t len;
  
      len = strlen(src);
      switch (len % 3) {
          do {
              *q++ = ',';
              case 0: *q++ = *p++;
              case 2: *q++ = *p++;
              case 1: *q++ = *p++;
          } while (*p);
      }
      *q++ = 0;
      return dst;
  }
  
  int main(void)
  {
      char str[] = "1234567890123";
      char res[32];
  
      printf("%s\n", money(str, res));
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>1,234,567,890,123
  </code></pre>
  
  <p>But I have problems trying to implement the same in Javascript:</p>
  
  <pre><code>function money(src, dst) {
      var len = src.length;
      var i = 0;
  
      switch (len % 3) {
          do {
              dst += ',';
              case 0: dst += src[i++];
              case 2: dst += src[i++];
              case 1: dst += src[i++];
          } while (src[i]);
      }
      return dst;
  }
  
  var str = "1234567890123";
  var res = "";
  
  console.log(money(str, res));
  </code></pre>
  
  <p>nodejs returns this error:</p>
  
  <pre><code>        do {
          ^^
  SyntaxError: Unexpected token do
  </code></pre>
  
  <p>My question is: Does javascript supports computed GOTO statements?</p>
  
  <p>P.D: I don't want an alternative, I just want to know why is not working.</p>
  
  <p>Related question: <a href="https://stackoverflow.com/q/817540/1606345">Does Duff's Device work in other languages?</a></p>