Skip to Content
App Inventor 2, 2nd Edition
book

App Inventor 2, 2nd Edition

by David Wolber, Hal Abelson, Ellen Spertus, Liz Looney
October 2014
Beginner to intermediate
360 pages
9h 3m
English
O'Reilly Media, Inc.
Content preview from App Inventor 2, 2nd Edition

Chapter 21. Defining Procedures and Reusing Blocks

Figure 21-0.
Defining Procedures: Reusing Blocks

Programming languages such as App Inventor provide a base set of built-in functionality—in App Inventor’s case, a base set of blocks. Programming languages also provide a way to extend that functionality by adding new functions (blocks) to the language. In App Inventor, you do this by defining procedures—named sequences of blocks—that your app can call just as it calls App Inventor’s predefined blocks. As you’ll see in this chapter, being able to create such abstractions is very important for solving complex problems, which is the cornerstone of building truly compelling apps.

When parents tell their child, “Go brush your teeth before bed,” they really mean, “Take your toothbrush and toothpaste from the cabinet, squeeze out some toothpaste onto the brush, swivel the brush on each tooth for 10 seconds (ha!),” and so on. “Brush your teeth” is an abstraction: a recognizable name for a sequence of lower-level instructions. In this case, the parents are asking the child to perform the instructions that they’ve all agreed mean “brush your teeth.”

In programming, you can create such named sequences of instructions. Some programming languages call them functions or subprograms. In App Inventor, they’re called procedures. A procedure is a named sequence of blocks that you can call from any place in an app.

Figure 21-15 is ...

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.
Start your free trial

You might also like

App Inventor

App Inventor

David Wolber, Hal Abelson, Ellen Spertus, Liz Looney
App Inventor 2 Essentials

App Inventor 2 Essentials

Felicia Kamriani, Krishnendu Roy
Hello App Inventor!

Hello App Inventor!

Carl Simmons, Paula Beer

Publisher Resources

ISBN: 9781491907214Errata Page