This code expands on the first example, adding loops, conditionals, and scoping