The Foreach loop and the For loop are different in that the latter uses an index to perform operations. We need a variable to control the flow, whose values form a range. Let us re-implement the same solution as that in Writing a more complex loop on a predefined array, but with a For loop construct instead.