Sunday, 15 February 2015

c# - Prefix and postfix increment in for loop -



c# - Prefix and postfix increment in for loop -

given next code

int j = 0; (int = 0; < str.length; ++i) { if (i==j) { console.writeline ("equal"); } j++; }

i expected ++i alter i initial 0 1 , i==j evaluated false.

but did not. why?

if have loop in form for (a; b; c) { d; }, can treat next while loop:

a; while(b) { d; c; }

as can see, increment doesn't occur until after first iteration, regardless of whether it's pre- or post- increment.

c# post-increment pre-increment

No comments:

Post a Comment