(MAI) Procedures Lesson
Procedures
In programming, we want to reuse code over and over again to save time and be more efficient.
A procedure is a sequence of blocks or code that accomplishes a specific task. In computer science, a procedure also might be called a function or a method.
App Inventor has Procedure Blocks
-
procedure do
-
procedure result
procedure do
Procedure names in an app must be unique. App Inventor will not let you define two procedures in the same app with the same name. You can rename a procedure at any time while you are building the app, by changing the label in the block. App Inventor will automatically rename the associated call blocks to match. The procedure do block is the same as a void method in Java. It will perform an action.
procedure result
When you create a procedure, App Inventor automatically generates a call block and places it in the My Definitions drawer. You use the call block to invoke the procedure.
The procedure result block is the same as a procedure do block, but calling this procedure returns a result. This is the same as a return method in Java.
After creating this procedure, a call block that needs to be plugged in will be created. This is because the result from executing this procedure will be returned in that call block and the value will be passed on to whatever block is connected to the plug.
[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION