[CSI] for post statement

Mikhail Nesterenko mikhail at cs.kent.edu
Thu Jul 14 22:37:00 EDT 2016


in the for-loop, there is no difference either syntactical or
semantical whether prefix or suffix form of the increment is
used. That is,

      for(int i=0; i < 20; ++i) ...

and
      for(int i=0; i < 20; i++) ...

are equivalent.

However, with more complicated types (to be studied in CSIB) the
suffix form is less efficient. So it is considered good style to avoid
using the suffix form.

Thanks,
--
Mikhail


> is there a syntactic reason why the post statement, in a for statement, has
> a convention of incrementing the loop variable with the suffix form?
> 
> If it doesn't matter which form you use(which i remember you saying in
> class) it would stand to reason that the convention would be to use the
> prefix form since its stylistically preferably.


More information about the cs13001 mailing list