in reply to Re: Auto-increment behaviour, is this normal and why?
in thread Auto-increment behaviour, is this normal and why?

Dear Kenneth,

Thank you for your answer.

So if understand what you expressed by "the print is a separate statement", the process is executing the following steps:

1. it tests the if condition
2. it incréments
3. it prints only if (1)

Thus because in the 1st case the if was false, the increment is done and the print not.
So at instruction 2 $i is already 1 and incremented to 2 before print, not after on the contrary of what I thought.
Then, as you shown me, when I write:
$i=0; for $lbl (qw/first middle last beyond/) {print $lbl.':',$i-1,',' if $i++}
I get what I expect:
middle:1,last:2,beyond:3,

All right, I was misunderstanding the time sequence when the increment applies with the if modifier (I still prefer it, it's shorter, I just need to learn to control it).

Thank you again very much.

Gilles.