Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes. It is bad practice. It will compile and run just fine, but in answer to your question, it is bad practice.</p> <p>If you want to manually update your iterator, use a <code>while</code> loop.</p> <p>Anything you can do with a <code>for</code> loop can also be done with a <code>while</code> loop. The choice in what loop to actually implement is a matter of readability. In <code>for</code> loops, people expect the iterator to be updated in the update statement and only in the update statement.</p> <p>If you can't figure out how to rewrite your loop so your iterator is updated only in the update statement, consider something like this:</p> <pre><code>for(int i=0; i&lt;someValue; ++i /*i also updated at line 18*/) </code></pre> <p>Just as an example. This is still worse than rewriting the code so it's not updated at line 18 (or whatever line) but far better than updating it at line 18 and not leaving the comment here in the update statement.</p> <p>Alternatively, per comments on this answer, try this:</p> <pre><code>for(int i=0; i&lt;someValue; /*see body*/) { //do stuff //update i //do stuff } </code></pre> <p>Now in this case, your update statement is completely empty, so even without the <code>/*see body*/</code> comment, anyone maintaining your code already know that <code>i</code> must be modified somewhere within the body. And the <code>++i</code> behavior from the update statement can be recreated simply by adding <code>++i</code> as the last line of the <code>for</code> loop.</p>
    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. 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