Repetition is another really useful function of programming.

https://www.youtube.com/embed/mgooqyWMTxk?start=0&end=36

<aside> 💡 A for loop is useful when you know how many times an instruction needs to be repeated.

</aside>

I want to repeat saying “Happy birthday!” 10 times. This is similar to what Mark Zuckerberg mentions in the video above without sending the message to individual users.

Untitled-2022-01-24-1326.png

The local variable

<aside> 💡 The local variable is similar to any other variable in a code file. It only exists in the for loop however. it can be named any suitable name. For example, if I am saying 5 times I could change i to greetingNumber.

</aside>

for greetingNumber in range(5):
		print("G'day mate")

https://youtube.com/shorts/cExxsVzsLDQ?si=PKyms77ft0Sj3i2I

The local variable is just a number. See what happens below when I print the local variable out.

https://replit.com/@bitFez/forexample1#main.py

The range is set as 5. So the instruction will repeat 5 times. Did you notice counting started at 0?

The range