@mjbaynes,
The issue is that the code is still executing in the void setup()
area, which is optimized to remove redundant code. After all, you should only initialize something once. Below is an example of what I think you are looking for.
In your example of Set-RepeatUntil-Change-Set-RepeatUntil-Change, the compiler recognizes the pattern and removes the redundant code leaving only one set of Set-RepeatUntil-Change. Each of the items can be considered a top level structure. In my example, the top level structure is Repeat3. The subordinate structure Set-RepeatUntil-Change-Set-RepeatUntil-Change is not optimized because they are required parts of the Repeat3.
Since the student exercise is to count lines, I would suggest placing the counting code in the Forever Loop. Keep in mind though, the exit condition for the void loop is something that will never change the truth value, like 1=1 is always true, and 1=2 is always false, so it will keep looping forever. I the example below.
You can set up a condition that will allow your code to execute a certain number of times, and then never execute again, even though it is still in a loop.
I hope this helps to explain what is going on.
Mike