Why identify int thisPin each time in 'for loop'?

In the program in which we turn on a sequence of LEDs, we identify thisPin as an int in the for loop within the void setup:

[for (int thisPin = 2; thisPin < 8; thisPin++) ]


and also in the void loop:

[for (int thisPin = 2; thisPin < 8; thisPin++) ]

Why isn't once enough? Or why couldn't we identify thisPin as an int in the initial setup (prior to the void setup)?

Since I just tested this--it works too.


bekathwia3 months ago

No particular reason other than code copy/paste modularity and ease of reading for beginners! Optimizing your code so it makes the most sense for you is a great way to learn more about programming!