Hacker News new | past | comments | ask | show | jobs | submit login

In this particular case I think you could do one of the following (ignoring the "while (true)" + "break" combination):

1:

  while (printOneStr(s[i]), ++i < n)
      printOneStr(", ");
2:

  goto start;
  do {
      printOneStr(", ");
  start:
      printOneStr(s[i]);
      ++i;
  } while (i < n);
But for this kind of code in general, I have thought that the "do while" statement should be extended to take an extra statement after the "while (cond)" part. It could still be an empty statement, with just a semicolon, like "do ... while (cond);", exactly like it's already used; but in cases like yours, you would be able to write this:

  do {
      printOneStr(s[i]);
       ++i;
  } while (i < n) {
      printOneStr(", ");
  }
As a bonus, the current mandatory semicolon after do-while statements would stop being a special case for the grammar of C.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: