Knowledge Builders

what are procedures in app inventor

by Robin Lowe Published 2 years ago Updated 2 years ago
image

Some programming languages call them functions or subprograms. In App Inventor

App Inventor for Android

App Inventor is a web application integrated development environment originally provided by Google, and now maintained by the Massachusetts Institute of Technology. It allows newcomers to computer programming to create application software for two operating systems: …

, they’re called procedures. A procedure is a named sequence of blocks that you can call from any place in an app. Figure 21-11is an example of a procedure that estimates the distance, in miles, between two GPS coordinates you send to it.

What is a procedure in App Inventor? An App Inventor procedure collects a sequence of blocks together into a group. You can then use the sequence of blocks repeatedly by calling the procedure. If the procedure has arguments, you specify the arguments by using name blocks.

Full Answer

How do I create a procedure in App Inventor?

In App Inventor, you define a procedure in a manner similar to how you define variables. From the Procedures drawer, drag out either a to procedure block or a to procedure result block. Use the latter if your procedure should calculate some value and return it (we'll discuss this approach a bit later in the chapter).

What is a procedure in an app?

Some programming languages call them functions or subprograms. In App Inventor, they're called procedures. A procedure is a named sequence of blocks that can be called from any place in an app. Figure 21-1 is an example of a procedure whose job is to find the distance, in miles, between two GPS coordinates you send to it.

How do I use call blocks in App Inventor?

You can then use the sequence of blocks repeatedly by calling the procedure. If the procedure has arguments, you specify the arguments by using name blocks. When you create a procedure, App Inventor automatically generates a call block and places it in the My Definitions drawer.

Can I have two procedures with the same name in inventor?

App Inventor will not let you define two procedures on the same screen 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.

What is a procedure?

What is an argument?

How to add arguments to a procedure?

About this website

image

What is a procedure block MIT?

A procedure is a sequence of blocks or code that is stored under a name, the name of your procedure block. Instead of having to keep putting together the same long sequence of blocks, you can create a procedure and just call the procedure block whenever you want your sequence of blocks to run.

What is procedural abstraction in MIT App Inventor?

The ability to name and later call a set of instructions like MoveMole is one of the key tools in computer science and is referred to as procedural abstraction.

What are the basic components of App Inventor?

Component ReferenceUser Interface components.Layout components.Media components.Drawing and Animation components.Map components.Chart components.Sensor components.Social components.More items...

What are parameters in App Inventor?

Parameters. A parameter (or an argument as they are called in App Inventor) is a place holder in a function or procedure definition. When you call the function you substitute a value for the parameter and the function uses that value in its computation.

What is abstraction procedure?

Procedural abstraction is when we write code sections (called "procedures" or in Java, "static methods") which are generalised by having variable parameters. The idea is that we have code which can cope with a variety of different situations, depending on how its parameters are set when it is called.

What are the benefits of procedural abstraction?

Advantages of Procedural AbstractionHides details.Allows us to think about the general framework & postpone details for later.Gives us building blocks we can reuse in other situations.Lets us use local names.Lets us easily replace implementations by better ones.

What are the two types of MIT App Inventor?

What is App Inventor?The App Inventor Designer, where you select the components for your app.The App Inventor Blocks Editor, where you assemble program blocks that specify how the components should behave. You assemble programs visually, fitting pieces together like pieces of a puzzle.

What are the three key parts of the App Inventor programming environment?

The App Inventor programming environment has three key parts:The Component Designer (Figure 1-2). You use it to select components for your app and specify their properties.The Blocks Editor (Figure 1-3). ... An Android device with which you can actually run and test your app as you are developing it.

How many blocks are there in App Inventor explain?

When you create a variable, App Inventor will automatically create two associated blocks, and place them in the My Definitions drawer: The global block gets the value of the variable. The set global block changes the value of the variable.

What is event driven programming in MIT App Inventor?

There are two types of events: user-initiated and automatic. Clicking a button, touching or dragging the screen, and tilting the phone are user-initiated events. Sprites colliding with each other or with canvas edges are automatic events. Another type of automatic event is a timer event.

Is App Inventor block-based?

MIT App Inventor is an intuitive, block-based programming environment that allows beginner programmers to build functional apps for smart phones and tablets.

What language does MIT App Inventor use?

It uses a block-based programming language built on Google Blockly (Fraser, 2013) and inspired by languages such as StarLogo TNG (Begel & Klopfer, 2007) and Scratch (Resnick et al., 2009; Maloney, Resnick, Rusk, Silverman, & Eastmond, 2010), empowering anyone to build a mobile phone app to meet a need.

Does procedural abstraction make code run faster?

Procedural abstraction improves the speed at which a program executes. This function checks if a character is a vowel. If it is, it returns true.

What are the advantages of using procedural abstraction try to name at least 2 advantages?

Some of the advantages of using procedural abstraction are that it helps debug your code and that it makes it a lot more organized. By making the code less complex, it helps make the code easier to understand and makes your program better overall.

What are the advantages of using procedural abstraction name at least 2 advantages?

Advantages of Procedural Abstraction Hides details. Allows us to think about the general framework & postpone details for later. Gives us building blocks we can reuse in other situations.

AppInventor file path - MIT App Inventor Help - MIT App Inventor Community

Hi, I tried to make an app with an extension that must be saved and then read. On SD card it works, but in the internal memory it doesn’t, and to those who don’t have the card it doesn’t work. My question is: what is the complete path with Appinventor files in the internal memory? Thanks in advance, The.

Making Lists (App Inventor 2) - Massachusetts Institute of Technology

What is a list? Many apps use lists of data. For example, a game may keep a list of high scores and your Facebook app keeps a list of your friends.

Sensor - Massachusetts Institute of Technology

Sensor Components. AccelerometerSensor; LocationSensor; OrientationSensor; AccelerometerSensor. This component senses the Android device's accelerometer, which detects shaking and measures acceleration in three dimensions.

MIT App Inventor Login - Massachusetts Institute of Technology

© 2012-2020 Massachusetts Institute of Technology; This work is licensed under a Creative Commons Attribution-ShareAlike 3.0; Terms of Service and Privacy Policy

What is displayList procedure?

The displayList procedure has limits in terms of its general usefulness, however. The procedure works for a specific list ( notes) and displays that list in a specific label ( NotesLabel ). You couldn't use it to display a different data list-say, a list of the app's users-because it is defined too specifically.

How does a program counter work in Note Taker?

When the program counter is performing the blocks within an event handler and it reaches a call block, it jumps over to the procedure and executes the blocks in it. When the procedure completes, the program counter jumps back to its previous location (the call block) and proceeds from there . So, for the Note Taker example, the remove list item block is performed; then the program counter jumps to the displayList procedure and performs its blocks (setting the NotesLabel.Text to the empty text, and the foreach ); and finally the program counter returns to perform the TinyDB1.StoreValue block.

How to define parameters in a procedure?

You define parameters for a procedure by clicking on the blue icon at the left-top of the procedure definition. For the displayList procedure, we would define a parameter named "list," as shown in Figure 21-7.

What is the extra slot in a procedure result block?

You'll notice that, when compared to the procedure block, the procedure result block has an extra slot at the bottom. You place a variable in this slot and it's returned to the caller. So, just as the caller can send data to a procedure with a parameter, a procedure can send data back with a return value.

What is redundant block?

The redundant blocks are the ones involving a foreach block (actually the foreach and the set NotesLabel.Text to above it). In all three foreach instances, the block's job is to display the notes list. In this app, this behavior needs to take place when a new item is added, when an item is removed, and when the list is loaded from the database at application launch.

How to change the name of a procedure block?

After dragging out a to procedure block, you can change its name from the default "procedure" by clicking the word "procedure" and typing the new name. The redundant blocks we're refactoring performed the job of displaying a list, so we'll name the procedure displayList, shown in Figure 21-3.

Why is it important to have a procedure block?

Procedures let you encapsulate code blocks and give those blocks a name. While you program the procedure, you focus solely on the details of those blocks. But in programming the rest of the app, you now have an abstraction-a name-that you can refer to at a high level.

Creating a Procedure with App Inventor

As a first example for creating a procedure, let's turn the five blocks that move the ball into a procedure named "MoveRight". In the Blocks Editor, we'll open the Definition drawer within the built-in palette, and drag the block labeled "procedure" into the application:

Generalizing the Procedure with Arguments

Some procedures just do their job and don't require any input data from the caller. For instance, the dad just says "Brush your teeth" and the kid does it (or doesn't).

Procedures with Return Values

Some procedures, like moveRight, just perform some operations. Others procedures are also are responsible for computing and returning a result to the caller. For instance, the + built-in block is a procedure that returns the sum of two things:

Key Concepts

Procedures make programs simpler through abstraction-- they allow a set of potentially many code blocks to be given a name, and that name be used to invoke those blocks.

Your Turn

Modify your BallAnimation project from your last tutorial by defining a procedure MoveHoriz that moves the ball an amount specified by an argument "distance".

What is a procedure?

A procedure is a set of instructions that perform a specific task or tasks. It may also be called a function. A recipe for banana bread is an example of a procedure. The baker must follow the instructions step-by-step to produce the bread.

What is an argument?

An argument is an input to our procedure. Some procedures require knowing some bits of information that change how the procedure is run. Let's look at the banana bread recipe example. Sometimes the baker may want to make two loaves of banana bread. Then the baker would double the amount of each ingredient called for in the recipe. This double or 2 is an argument to our procedure since this changes how much of our ingredients we mix together.

How to add arguments to a procedure?

When you create a procedure, you can use the mutator button to add arguments. By hovering your mouse over an argument, you will see a get and set block appear. Drag these blocks onto your screen to use them. This procedure takes two arguments: x and y. Then it returns the result of adding x to y.

image

Eliminating Redundancy

Image
Take a look at the code blocks in Figure 21-2. See if you can you identify the redundant ones. Figure 21-2. A Note Taker app with redundant code The redundant blocks are the ones involving a foreach block (actually the foreach and the set NotesLabel.Text to above it). In all three foreachinstances, the block's job is to dis…
See more on appinventor.org

Defining A Procedure

  • Let's build a procedure to do the job of the redundant code blocks from Figure 21-2. In App Inventor, you define a procedure in a manner similar to how you define variables. From the Procedures drawer, drag out either a to procedure block or a to procedure resultblock. Use the latter if your procedure should calculate some value and return it (we'll discuss this approach a b…
See more on appinventor.org

Calling A Procedure

  • Procedures, like displayList and "brush your teeth," are entities with the potential to perform a task. However, they'll only perform that task if they are called upon to do so. Thus far, we've created a procedure but haven't called it. To call a procedure means to invokeit, or to make it happen. In App Inventor, you calla procedure by dragging out...
See more on appinventor.org

The Program Counter

  • To understand how the call block works, think of an app as having a pointer that steps through the blocks performing functions. In computer science, this pointer is called the program counter. When the program counter is performing the blocks within an event handler and it reaches a call block, it jumps over to the procedure and executes the blocks in it. When the procedure complet…
See more on appinventor.org

Adding Parameters to Your Procedure

  • The displayListprocedure allows redundant code to be refactored into a single place. The app is easier to understand because you can read the event handlers at a high level and generally ignore the details of how a list is displayed. It is also helpful because you may decide to modify how you display the list, and the procedure allows you to make such a modification in a single place (inst…
See more on appinventor.org

Returning Values from A Procedure

  • There is still one issue with the displayList procedure in terms of its reusability-can you figure out what it is? As it's currently written, it can display any list of data, but it will always display that data in the label NotesLabel. What if you wanted the list to be displayed in a different user interface object (e.g., you had a different label for displaying the userList)? One solution is to reconceptual…
See more on appinventor.org

Reusing Blocks Among Apps

  • Reusing code blocks through procedures need not be restricted to a single app. There are many procedures, like listToText, that could be used in just about any app you create. In practice, organizations and programming communities build up code libraries of procedures for their domains of interest-for example, a code library of animation procedures. Typically, programmin…
See more on appinventor.org

A Second Example: Distancebetweenpoints

  • With the displayList (listToText) example, we characterized procedure definition as a way to eliminate redundant code: you start writing code, find redundancies as you go along, and refactor your code to eliminate them. Generally, however, a software developer or team will design an app from the beginning with procedures and reusable parts in mind. This sort of planning can save y…
See more on appinventor.org

Summary

  • Programming languages like App Inventor provide a base set of built-in functionality. Procedures let app inventors extend that language with new abstractions. App Inventor doesn't provide a block for displaying a list, so you build one. Need a block for computing the distance between GPS coordinates? You can create your own. The ability to define higher-level procedure blocks is the …
See more on appinventor.org

1.Videos of What Are Procedures in App Inventor

Url:/videos/search?q=what+are+procedures+in+app+inventor&qpvt=what+are+procedures+in+app+inventor&FORM=VDRE

13 hours ago What is a procedure in App Inventor? An App Inventor procedure collects a sequence of blocks together into a group. You can then use the sequence of blocks repeatedly by calling the …

2.Procedures - Massachusetts Institute of Technology

Url:http://appinventor.mit.edu/explore/ai2/support/concepts/procedures.html

18 hours ago Define Procedures to Create New Blocks. Introduction. Introduction to Procedures. Creative Nugget: Procedures. Creating Procedures: Logo. Procedures, Logo 1 Conceputalize. …

3.How to use Procedures in MIT App Inventor 2 - YouTube

Url:https://www.youtube.com/watch?v=rgn1nrp8lxc

18 hours ago In App Inventor, they’re called procedures. A procedure is a named sequence of blocks that can be called from any place in an app. Figure 21-1 is an example of a procedure whose job is to …

4.CHAPTER 21 Defining Procedures: Reusing Blocks - Appinventor

Url:http://ai2.appinventor.org/assets/pdf/ch21Procedures.pdf

1 hours ago  · Learn how to use or make procedures in App Inventor. Today I share some information about procedures. Procedures are basically functions or a series of steps done in …

5.Learn App Inventor: Procedures - YouTube

Url:https://www.youtube.com/watch?v=3eHQsATBhcI

3 hours ago Creating a Procedure with App Inventor In the lesson on timer events and animation, we learned that you can move an image (or a ball) right with the following blocks: As a first example for …

6.Procedures - AppInventor.org: Democratizing App …

Url:https://sites.google.com/site/appinventor/functions

36 hours ago

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9