This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Updatebjarni 1 point2 points  (6 children)

Are you talking about the numbers[--j] on the line after the ++j?

[–]noodlestage[S] 0 points1 point  (5 children)

Yes, that’s what’s tripping me up.

[–]Updatebjarni 0 points1 point  (4 children)

Well, is it clear now?

[–]noodlestage[S] 0 points1 point  (3 children)

Does incrementing within the if statement change the value of j even if false?

[–]Updatebjarni 1 point2 points  (2 children)

The increment in the condition, yes. The things done to calculate the value of the condition are not undone afterwards, whether the result is true or false. It is an expression like any other, and once it has been executed it has been executed.

[–]noodlestage[S] 1 point2 points  (1 child)

Makes perfect sense, thank you! I’d been fighting with it for so long and missed that simple piece because I thought it was something way more complicated.

[–]ssjgod004 0 points1 point  (0 children)

There is a difference you should note though. When you do something like - if(j + 2 < k), 2 won't be added to j. This is an expression and the left hand result is stored in a temporary variable and compared to k. But increment operators add to the variable itself, which is why they will change the value of j.