Learning Python: Part 6: Loops

Learning Python

Python is a general-purpose interpreted programming language. It emphasizes readability through the use of whitespace and supports multiple programming paradigms such as functional and object-oriented models.


Loops

To help with tasks that need to repeat or continue until something happens, there is a programming concept called loops.

In Python, loops look like functions in structure but work in a different way. They have their keywords, what to test, and end in a colon. The code to run in the loop is “under” (tabbed from the left margin).

While

A while loop works on conditional statements. For as long as the statement is true, the loop will continue to run.

For… in…

The forin… keywords are primarily used for running in fixed cycles. They are often used in conjunction with lists (for moving through them one-by-one) or in fixed ways using another function, range().

Play with the example on Repl.it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.