in reply to 'prev' in for loop

You're not "moving your index" to the last one when using last. last will terminate the loop immediately. next will terminate the current iteration, which will cause the condition to be tested again. This may cause the end of the loop, or its "next" iteration, with any side-effects of the guard in effect. redo will restart the current iteration, without any testing of the condition.

I've no idea what prev should do. Rollback the current iteration?

Perl --((8:>*

Replies are listed 'Best First'.
Re^2: 'prev' in for loop
by kulls (Hermit) on Dec 07, 2005 at 04:04 UTC
    hi,
    I updated my question too.if my loop supports  next if($_ eq 'foo') then, why not it's support  prev if($_ eq 'foo')?
    -kulls
      Because that's how Perl was designed. It would IMO be more confusing than supportive to the programmer. Also, like Perl Mouse said, last and next don't influence the loops position (directly), more the control flow. 'last' exits the block, so the calling run was the /last/ one. 'next' jumps to the end of the block so the /next/ run will start if there is any. 'redo' redoes the block without going to the next iteration.

      Ordinary morality is for ordinary people. -- Aleister Crowley