There are just two cases to be concerned about: 1/ $var is local to the loop, 2/ $var is global to the loop.
1/ If $var is local to the loop the desired behaviour is that you get a fresh version of $var each time through the loop. In that case use a my declaration where the first value is assigned to $var within the loop.
2/ If you want $var to retain some previous value from one iteration of the loop to the next (maybe you are looking for a largest value or something) then $var should be global to the loop. In that case use a my declaration just before the loop and assign an appropriate initial value if required.
In reply to Re: my within a loop
by GrandFather
in thread my within a loop
by palkia
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |