There are many ways that conditionals show up in coding. The most clear are the cases where we use if/elif/else or loops, but there are some less obvious cases. One thing that they all have in common is that, when represented by a flowchart, the symbol is the diamond (decision box) that evaluates if a condition is true or not.
Decisions and loops are closely tied to making boolean decisions (relational and boolean operators) so understanding these is crucial to being able to construct many of the conditional structures.
The following are the cases where decisions are made and conditional execution takes place:
if elif else
try except
assert raise
Most have the same syntax, but not all. In these cases here, one path or another is chosen.
Loops are a special form of decisions, where code will repeat until a condition is met. An excellent resource on this topic is Prof Cravens page on Quiz games with conditionals.
There are two major types of loops in Python, for loops and while loops. If you want to repeat a certain number of times, use a for loop. If you want to repeat until something happens (like the user hits the quit button) then use a while loop.
The forms of loops we have in Python are:
while loop
for loop
recursion
Recursion is a particular form of repeating code- it is where a function calls itself until a base case is reached.
For some nice examples of loops used in games, check out Paul Cravens page on loops.
For coding challenges to really test your grasp of loops, check these loop challenges.