260 likes | 392 Views
Dr. José M. Reyes Álamo. Loops, Databases, Procedures, and Lists. Outline. Loops Databases Procedures Lists. Loops. Some times you need to repeat…. While the test is TRUE do. Some times you need to repeat…. For each element in the list do. Some times you need to repeat….
E N D
Dr. José M. Reyes Álamo Loops, Databases, Procedures, and Lists
Outline • Loops • Databases • Procedures • Lists
Some times you need to repeat… While the test is TRUE do
Some times you need to repeat… For each element in the list do
Some times you need to repeat… For each value of i in the range of start to end on steps of step do
Permanent Storage • TinyDB • Persistent storage in your device • TinyWebDB • Persistent storage in the Web
TinyDB Grocery List
What is a procedure? A procedure is a named sequence of blocks that encapsulate some functionality and can be called from any place in your app.
More about procedures • Procedures are an abstraction since they represent a recognizable name for a sequence of lower-lever instructions. • In other programming languages procedures are called functions or subprograms.
Why are procedures useful? Procedures can be a good tool to develop large apps. You create new functionality by using procedures. You can use them to break down a large problem or project into more manageable sub problems. While designing the app, you can define a procedure ignoring the details of how it works and refer to the empty procedure. When your finish your design, you can add code to the empty procedures to complete the functionality of your app. You can put chunks of code in one place and call it from various places in your app.
Two blocks to define procedures • The procedure block collects a sequence of blocks together. • When you create a procedure, AppInventor automatically generates a call block and places it in the My Definitions drawer. • You use the call block to invoke the procedure. • The procedureWithResults block works similarly to procedure but also returns a result. • After the procedure executes, the result is returned to the block connected to the return socket.
Refactoring • Refactoring is programming technique that consist on reorganizing the code, for example create a procedure to substitute redundant code, to make it easier to maintain and easier for the programmers to work with.
What is a list? They are variables that instead of holding a single value, they hold several values distinguished by an index. Simple variables score = 100 phoneNumber = 201-122-4322 Lists bestScores = [100, 98, 89] myContactsPhoneNumbers = [201-122-4322, 803-234-3293, 977-121-5383]
What is a list? Simple variables score = 100 phoneNumber = 201-122-4322 Lists bestScores = [100, 98, 89] myContactsPhoneNumbers = [201-122-4322, 803-234-3293, 977-121-5383]
OpenLab and Blackboard • Finish your labs and post them in OpenLab. • Finish quizzes on Blackboard. • Work on your Project. • Study for the Final Exam.