loops, databases, procedures, and lists
DESCRIPTION
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…. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/1.jpg)
Loops, Databases, Procedures, and Lists
Dr. José M. Reyes Álamo
![Page 2: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/2.jpg)
2
Outline
Loops
Databases
Procedures
Lists
![Page 3: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/3.jpg)
Loops
![Page 4: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/4.jpg)
4
Some times you need to repeat…
While the test is TRUE do
![Page 5: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/5.jpg)
5
![Page 6: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/6.jpg)
6
Some times you need to repeat…
For each element in the list do
![Page 7: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/7.jpg)
7
![Page 8: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/8.jpg)
8
Some times you need to repeat…
For each value of i in the range of start to end on steps of step do
![Page 9: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/9.jpg)
9
![Page 10: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/10.jpg)
Databases
![Page 11: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/11.jpg)
11
Permanent Storage
• TinyDB – Persistent storage in your device
• TinyWebDB– Persistent storage in the Web
![Page 12: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/12.jpg)
12
TinyDB
Item (tag) Quantity (valueToStore)
Pasta 1 Box
Sauce 1 Jar
Grocery List
![Page 13: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/13.jpg)
13
![Page 14: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/14.jpg)
14
![Page 15: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/15.jpg)
Procedures
![Page 16: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/16.jpg)
16
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.
![Page 17: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/17.jpg)
17
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.
![Page 18: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/18.jpg)
18
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.
![Page 19: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/19.jpg)
19
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.
![Page 20: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/20.jpg)
20
Refactoring
![Page 21: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/21.jpg)
21
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.
![Page 22: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/22.jpg)
Lists
![Page 23: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/23.jpg)
23
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]
![Page 24: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/24.jpg)
24
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]
![Page 25: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/25.jpg)
25
List operations
![Page 26: Loops, Databases, Procedures, and Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062516/56812a92550346895d8e3fd2/html5/thumbnails/26.jpg)
26
OpenLab and Blackboard
• Finish your labs and post them in OpenLab.
• Finish quizzes on Blackboard.
• Work on your Project.
• Study for the Final Exam.