Staying in the Loop

Computers are good at doing things over and over again. Humans tend to find repetitious tasks boring. That's why we program with loops. Loops are code blocks that tirelessly repeat until the task is finished. Python has for loops and while loops. Both kinds of loops have these things in common:

• They start with a keyword (for or while), followed by an expression and ending with a colon.

• They are code blocks, and the code inside them is indented.

TECHNICAL The right loop for your task depends on several factors. See the STUFF section "Choosing Your Loop" later in this chapter.

Was this article helpful?

0 0

Post a comment