Is there a difference in ++i and i++ in a for loop? Is it simply a syntax thing?
Is there a difference in ++i and i++ in a for loop? Is it
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
a++ is known as postfix.
add 1 to a, returns the old value.
++a is known as prefix.
add 1 to a, returns the new value.
C#:
Output:
foreachandwhileloops depend on which increment type you use. With for loops like below it makes no difference as you’re not using the return value of i:If the value as evaluated is used then the type of increment becomes significant: