I got into the habit of using while loops because it deals with spaces in input better or so I've found., but mostly I can work in "blocks" up to the pipe "|" is one block. Test. Debug. Then on to the next block. That makes It easier to debug on the command line, where most of these start. 

Not using seq makes the script too bashey :) but that argument holds little water I know.