Scope
In the introduction for this hour, you learned that subroutines are used to take pieces of code and bundle them up and give them a name. You then can use this name to execute the code whenever you need it. You can also write the code within the subroutine so that it functions autonomously. That is, you can make it run and produce its return value using nothing but its arguments, the language's built-in functions and operators, and literal expressions within it. In that case, you can reuse the subroutine in other programs, because it no longer relies on the context it's being called in; it simply takes its arguments and data defined internally and produces a return value. The subroutine becomes a black box—stuff goes in, stuff comes out—and ...
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