Coding 101 14: Thrown a For Loop
00:00
Hosts: Fr. Robert Ballecer, SJ and Shannon Morse
Guest: Dale Chase
Welcome to Coding 101 - It's the TWiT show that gives YOU the knowledge to live in the wonderful world of the programmer. This week we are introducing our newest module, Python with Code Warrior Dale Chase!
To see all the code used in today's episode, go to Our Github Repository for Module 2
Loops (Recap)
* As we may recall, loops are an easy way to reuse code.
* It allows us to "loop" a section of code so that it doesn't have to be writen over and over.
For Loops
For Loops use a "range" function to determine the start and the end of the loop.
Code Sample:
for counter in range(0,3):
- print counter
* Notice how the counter print statement ran from 0 - 2 and NOT 0 - 3. That's because the counter is incremented at the end of each loop and each loop does a pre-test. After the code prints "2", 1 is added to the counter. When it loops back to the range function, the counter is "3" - Since we told
Comments
00:00