[Bluej-discuss] For Loop Doubt again....

Bryan J. Higgs bhiggs at rivier.edu
Wed Mar 8 14:12:37 GMT 2006


To say it as clearly as I can:

    * Both j++ and ++j are expressions that return values
    * Both expressions result in the value of j being incremented (this
      is known as a 'side-effect' of the expression)
    * The difference between the two expressions is that the
      (post-increment) expression j++ returns the original value of j
      (that is, the expression is evaluated before the increment
      occurs), while the pre-increment expression ++j returns the
      incremented value of j (that is, the expression is evaluated after
      the increment occurs)
    * If the value of the expression is ignored (as in your for loop
      example), then there is no observable difference between j++ and ++j.

I hope that helps.

Regards

Bryan


Namit TClaw wrote:
>
> Thanks for the help with post and pre increment….. But my doubt is 
> that does it have any special effect when placed in the update 
> expression of for loop…..
>
> for(int j=1;j<=5;j++)
>
> > System.out.println(j);
>
> >
>
> And
>
> >
>
> > for(int j=1;j<=5;++j)
>
> > System.out.println(j);
>
> Regards,
>
> Namit.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> mailing list bluej-discuss at bluej.org
> To unsubscribe or change your preferences, go to
> http://lists.bluej.org/mailman/listinfo/bluej-discuss
>   


More information about the bluej-discuss mailing list