Python Loops and Iteration
Python Loops & Iteration - Cmpnote Topic: Loops and Iteration Mastering the power of repetition and automation. 1. The Concept of Iteration In programming, Iteration simply means repeating a process. Instead of writing the same line of code 100 times, we use a loop. Python provides two main types of loops: the For Loop and the While Loop . 2. The "For" Loop (Fixed Repeats) Use a for loop when you know exactly how many times the code should run. It is often paired with the range() function. # range(start, stop) for i in range(1, 6): print("Attempt number:", i) Pro Tip: range(1, 6) starts at 1 and stops at 5. It never includes the final "stop" number! 3. The "While" Loop (Condition Based) A while loop keeps ...