PBP: 083 Redoing

This Practice is to encourage the use of a for loop instead of while plus a counter.  It reminds us of redo, a Perl feature I always forget which lets us do the loop over at this iterator.  If the only place the while loop does not increment is to try again, a redo fits perfectly.  If the loop has to do more complex changes to the iterator – back up, start over at zero, whatever – then you’ll sill need the more complex while+counter.

I always forget redo, which is embarrassing.  It’s a core feature of Perl, and a useful loop control mechanism.  It can make complex structures easier, and that’s an excellent reason to know it.

Leave a Reply