Chapter 10: Using Loops
In the previous chapter, we started dealing with scripting, and we did a lot of learning about how scripts work and how they are structured. However, we missed a huge topic in scripting – influencing the order in which commands are executed when a script is run. There are a couple of things that we need to cover here, since there are multiple ways we can influence what is going to be the next command executed in a script.
We are going to start with a concept we call iterators or, more commonly, loops. There are a lot of things in everyday tasks that need to be done repeatedly, usually changing just one small thing in every iteration. This is where looping comes in.
We will cover the following recipes in this chapter:
- The
for
loop break
andcontinue
- The
while
loop - The
test-if
loop - The
case
loop - Logical looping with
and
,or
, andnot