Repetition means performing a task or sequence of steps more than once. In programming, it appears both as repeating string values and as repeating commands with loops. section 8.2 section 16.1
Recognize repetition in two common forms:
- String repetition multiplies a string by an integer: 3 * "a" produces "aaa". Writing "-" * 10 creates ten unknown-letter markers without typing each character. section 8.2
- Task repetition uses loops to execute a set of statements many times, possibly changing a value on each pass. section 16.1
- Every repetition needs a clear stopping rule. “Lather, rinse, repeat” can continue forever, while “repeat as needed” checks whether another pass is required. section 16.1
- A recipe or flowchart can show repetition by directing an arrow back to the first step in the repeated sequence. section 2.2
Repeating a command three times
for v in range(3): print("var v is", v) Python assigns 0, then 1, then 2 to v and runs the indented print statement after each assignment. The loop therefore performs the statement three times. You can replace 3 with a variable such as n_times when the repetition count changes. section 16.3
Listing 16.2. A for loop that prints the loop variable value
for v in range(3): #1
print("var v is", v) #2
Inspect the compact for-loop listing, then compare it with the unrolled version to trace each repeated execution. section 16.3

