whole list of if statements |
The line 9 in CodeWriter's program requires only a three-branch
if .. else if .. else ..
. Does that warrant the "whole list" moniker?
The "use for loops" probably means using two for-loops to print one line.
The first loop will print required number of '-' before the first digit.
Then you print the digit.
The second loop will print required number of '-' before the second digit.
Then you print the digit.
Line is complete.
Outer loop repeats the above block for each line.
In CodeWriter's version your math has to resolve two things: which "cells of 2D array" should show digits, and what are those digits.
In "loops, no ifs" version your math has to resolve two things too: how many '-' before each digit, and what are those digits.
(I do assume that the input number is always less than ten. The "alignment" gets unnecessarily "interesting", when numbers can have more than one digit.)