Chapter 10
Adding Structure to Your Scripts
IN THIS CHAPTER
Adding decision-making to your scripts
Using recursive functions
Repeating tasks
Defining menus
The scripts and functions you have created so far have all performed a series of tasks, in order, one at a time. However, sometimes it’s important to skip steps or to perform the same step more than once. Humans make decisions about what to do with ease, but computers need a little help by using conditional statements that allow actions only when needed. Humans also know when to do something more than once, but computers need help in this regard as well, by using loop statements that define when and how many times to perform a task. This chapter helps you understand the use of both conditional and loop statements when creating scripts and functions.
As part of discovering how decisions are made and just how repetition works, you see two practical examples of how to employ your new skills. The first is a technique called recursion, which is simply a method of performing a task more than once, but in an elegant way. Using recursion ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access