Skip to main content

Loops

  • Chapter
  • First Online:
Make Your Own Python Text Adventure
  • 4595 Accesses

Abstract

The real power of computers is in their ability to execute repetitive tasks without complaint. A CPU is perfectly happy chugging along flipping bits until it burns out. A calculator will keep calculating for as long as you give it numbers to work with. And sure—keep mashing F5 on your favorite web site that is currently having server trouble—your router won't care.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

eBook
USD 16.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 16.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    It is a convention to use variable i in loops that have a counter; this is one of the few exceptions where it is okay to not use a descriptive variable name!

  2. 2.

    You can actually store a really huge number of items in a tuple, but if you need more than a few variables, you should rethink your choice to use a tuple.

  3. 3.

    The object is called an iterator if you want to research more. The range() function also returns an iterator.

  4. 4.

    Just like using i is a convention, j is a convention in a nested loop. If you really need them, k and l are next.

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Phillip Johnson

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Johnson, P. (2018). Loops. In: Make Your Own Python Text Adventure. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-3231-6_7

Download citation

Publish with us

Policies and ethics