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

To the author: the initial for loop is not equivalent to a do/while loop. The condition of the for loop is executed before the loop runs. e.g. the loop body will never run if *count == 0.



There’s an if statement around the do while loop on that page, so that the do while loop also will not run if *count == 0.

The code snippets

    for (int i = 0; i < *count; ++i) {
        str[i] = 0;
    }
and

  if (*count > 0) {
    long idx = 0;
    do {
      str->__data[idx] = 0;
      idx += 1;
    } while (idx <= *count);
  }
Will produce the same changes to the string data given the same count.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: