Yes. It looks about the same as the previous absolute value problem.
Many programs have this over-all design. Almost always there is an initialization step. Part of initialization is to prepare the first item of data. The loop tests if there actually is data to be processed and then processes it. At the bottom of the loop body the next item of data is prepared, if there is more data. Then back to the top of the loop. When there is no more data, the loop terminates. The wrap-up step does whatever remains to be finished. These steps are so common you can nearly always start with the this design for any program.
A good first design step is to determine what the main loop should do. Of course, there will likely be nested loops and ifs, possibly several levels down, within the body of the main loop. But if you have correctly designed the outer loop you have made great progress.
The key to figuring out what the outer loop should be is to look at the data to be processed. Data very often comes in a sequence of discrete chunks, like beads on a string. Then the outer loop should process the data one chunk at a time. For example, sometimes text data can be processed character by character. The chunk size in this case is "character." Sometimes text data must be processed word by word. The chunk size in this case is "word." Sometimes text data must be processed line by line.
Is the for
statement allowed in structured code?