An Introduction to Python: Control Structures

Control Structures

Table of Contents

...If, While, For, Try...

This is just going to be some boring examples of control structures. I don't have a lot to say about this stuff, but it would be a bad form not to at least mention them. So here we go.

If

Notice the new keywords if, elif, else, and, or, and not. That's pretty much all there is to it.

While

...zzzzzzzz...

Oh, yes, "While" loops!

Here's another example:

For

For loops are actually very interesting because they don't behave just like C for loops, although they can. For loops in Python iterate over Lists instead of just incrementing integers. They are probably my favorite constructs in Python, because the syntax is very intuitive and just downright pleasant.

Aren't they just lovely?

Control Statements

They work in pretty much the exact same way. Here's some quick examples:

What about... ?

Case structures?

Try

These are really quite a bit more complicated, try and except are going to be handled later under the topic of "Exceptions", so check it out there if you're interested.


Table of Contents