SlideShare a Scribd company logo
1 of 29
Variables in MIT App
Inventor
Global Variable and Local Variable
What is Global Variable?
 A global variable is a variable that can be accessed in multiple scopes. This means that wherever you are in the
program you can use that variable; get its current value or set its value to something else. Global variables are created
using the initialize global name to block found in the Variables drawer.
What is Local Variable?
 A local variable is a variable that is declared within a function or it is an argument passed into a function. This means
that you can only access these variables in that specific function where they are declared or passed in as an argument.
Variables Overview
 The Variables drawer provides blocks to create, get, and set both global and local variables.
Explanations of all of the blocks available in this drawer can be found on the Variables page.
There are five main types of
variable blocks:
‱ initialize global name to
‱ get
‱ set
‱ initialize local name to in (do)
‱ initialize local name to in (return)
“initialize global name to”
This block is used to create global variables. It takes in any type of value as an
argument. Clicking on name will change the name of this global variable. Global
variables are used in all procedures or events so this block will stand alone.
Global variables can be changed while an app is running and can be referred to
and changed from any part of the app even within procedures and event handlers.
You can rename this block at any time and any associated blocks referring to the
old name will be updated automatically.
“get”
This block provides a way to get any variables you
may have created.
“set”
This block follows the same rules as “get”. Only variables in scope will be
available in the dropdown. Once a variable v is selected, you can attach a
block to give v a new value.
“initialize local name to - in (do)”
 This block is a mutator that allows you to create new variables that are only used in the procedure you run in the DO part of the
block. This way all variables in this procedure will all start with the same value each time the procedure is run. NOTE: This
block differs from the block described below because it is a DO block. You can attach statements to it. Statements do things.
That is why this block has space inside for statement blocks to be attached.
 You can rename the variables in this block at any time and any corresponding blocks elsewhere in your program that refer to
the old name will be updated automatically
“initialize local name to - in (return)”
 This block is a mutator that allows you to create new variables that are only used in the procedure you run in the RETURN
part of the block. This way all variables in this procedure will all start with the same value each time the procedure is run.
NOTE: This block differs from the block described above because it is a RETURN block. You can attach expressions to it.
Expressions return a value. That is why this block has a socket for plugging in expressions.
 You can rename the variables in this block at any time and any corresponding blocks elsewhere in your program that refer
to the old name will be updated automatically
Global Variable Example
Take out a get block and click the dropdown. There will be no variables to select. Create a global variable and
name it count and initialize it to 0. Click on the dropdown of the get block. You can now see count available to
choose. Once you have created a global variable, it will always be available in the dropdown of get .
Local Variable Example
Create a local variable using initialize local name to in do block and name it a. Now drag out a set block and put it outside of
the initialize local name to in do block. Click on the dropdown of the set block. You will not see a as a choice in the dropdown.
This is because the set block is out of the scope of the local variable's domain. Move the block inside of the do part of
the initialize local name to in do block. Click the dropdown of the set block. Now a is available to choose.
Variable Labels
 Notice how when you use a get or set block for a global variable. The block will
say global name.
 When using get or set blocks for local variables, the block will only say name. Remember
that local variables include variables created from arguments to procedures or event
handlers, variables created for use in for loops, or initializing local variables for an
expression or return statement by using the orange local variable initialize blocks.
Why would I ever need to use local variables?
Sometimes you may need to create a new variable within a procedure and only want that procedure
to be able to use it.
In this example, we use a local variable, height, to store the height of the triangle whose hypotenuse
and base we're given as arguments. We might have a different procedure that uses height as an
argument so we would not be able to use a global variable. To make sure of that, we use local
variables so that the height in the right context is only available in the procedure where it is used.
Sometimes it might just be easier to have local variables rather than creating many new global ones.
Or it might allow us to use less blocks.
MIT App Inventor Control Blocks
(Loops and Conditions)
“if & else if”
Tests a given condition. If the condition is true, performs the
actions in a given sequence of blocks; otherwise, the blocks
are ignored.
Tests a given condition. If the condition is true, performs the
actions in the -then sequence of blocks; otherwise, performs
the actions in the -else sequence of blocks.
Tests a given condition. If the result is true, performs the actions in the
-then sequence of blocks; otherwise tests the statement in the -else if
section. If the result is true, performs the actions in the -then sequence
of blocks; otherwise, performs the actions in the -else sequence of
blocks.
“for each number from to”
Runs the blocks in the do section for each numeric value in the range starting from from and ending at to,
incrementing number by the value of by each time. Use the given variable name, number, to refer to the current value.
You can change the name number to something else if you wish.
“for each item in list”
Runs the blocks in the do section for each item in the list. Use the given variable name, item, to refer to the current list
item. You can change the name item to something else if you wish.
“for each key with value in dictionary”
Runs the blocks in the do section for each key-value entry in the dictionary. Use the given variables, key and value, to refer to the key
and value of the current dictionary entry. You can change the names key and value to something else if you wish.
“while”
Tests the -test condition. If true, performs the action given in -do , then tests again. When test is false, the block ends and the
action given in -do is no longer performed.
if then else
Tests a given condition. If the statement is true, performs the actions in the then-return sequence of blocks and returns the then-
return value; otherwise, performs the actions in the else-return sequence of blocks and returns the else-return value. This block is
similar to the ternary operator (?:) found in some languages.
“do with result”
Sometimes in a procedure or another block of code, you may need to do something and return something,
but for various reasons you may choose to use this block instead of creating a new procedure.
“evaluate but ignore result”
Provides a “dummy socket” for fitting a block that has a plug on its left into a place where there is no
socket, such as one of the sequence of blocks in the do part of a procedure or an if block. The block you
fit in will be run, but its returned result will be ignored. This can be useful if you define a procedure that
returns a result, but want to call it in a context that does not accept a result.
open another screen
Opens the screen with the provided name.
The screenName must be one of the Screens created using the Designer. The screenName should be
selected from the connected screen name dropdown block.
If you do open another screen, you should close it when returning to your main screen to free system
memory. Failure to close a screen upon leaving it will eventually lead to memory problems.
App developers should never close Screen1 or use this block to return to Screen1. Use the close screen block
instead.
open another screen with start value
Opens another screen and passes a value to it.
get plain start text
get start value
Returns the plain text that was passed to this screen when it was started by another app. If no value was passed, it returns the
empty text. For multiple screen apps, use get start value rather than get plain start text.
Returns the start value given to the current screen.
This value is given from using open another screen with start value or close screen with value.
close screen
close screen with plain text
close screen with value
close application
Closes the current screen.
Closes the current screen and passes text to the app that opened this one. This command is for returning text to non-App
Inventor activities, not to App Inventor screens. For App Inventor Screens, as in multiple screen apps, use close screen
with value, not close screen with plain text.
Closes the current screen and returns a value to the screen that
opened this one.
Closes the application.
break
When looping using the for range, for each, or while blocks it is sometimes useful to be able to exit the loop early.
The break allows you to escape the loop. When executed, this will exit the loop and continue the app with the statements
that occur after the loop in the blocks.
Variables in MIT App Inventor powerpoint

More Related Content

Similar to Variables in MIT App Inventor powerpoint

The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185Mahmoud Samir Fayed
 
Delphi qa
Delphi qaDelphi qa
Delphi qasandy14234
 
Lecture 3 Conditionals, expressions and Variables
Lecture 3   Conditionals, expressions and VariablesLecture 3   Conditionals, expressions and Variables
Lecture 3 Conditionals, expressions and VariablesSyed Afaq Shah MACS CP
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio) rnkhan
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)rnkhan
 
Static keyword u.s ass.(2)
Static keyword u.s ass.(2)Static keyword u.s ass.(2)
Static keyword u.s ass.(2)Syed Umair
 
The Ring programming language version 1.6 book - Part 75 of 189
The Ring programming language version 1.6 book - Part 75 of 189The Ring programming language version 1.6 book - Part 75 of 189
The Ring programming language version 1.6 book - Part 75 of 189Mahmoud Samir Fayed
 
Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developerSalvatore Fazio
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classesFajar Baskoro
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]srikanthbkm
 
Storage Class Specifiers
Storage Class SpecifiersStorage Class Specifiers
Storage Class SpecifiersReddhi Basu
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxmary772
 
Handout # 4 functions + scopes
Handout # 4   functions + scopes Handout # 4   functions + scopes
Handout # 4 functions + scopes NUST Stuff
 

Similar to Variables in MIT App Inventor powerpoint (20)

Computer programming 2 Lesson 6
Computer programming 2  Lesson 6Computer programming 2  Lesson 6
Computer programming 2 Lesson 6
 
The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185
 
Ppt on java basics
Ppt on java basicsPpt on java basics
Ppt on java basics
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 
Lecture 3 Conditionals, expressions and Variables
Lecture 3   Conditionals, expressions and VariablesLecture 3   Conditionals, expressions and Variables
Lecture 3 Conditionals, expressions and Variables
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio)
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)
 
Static keyword u.s ass.(2)
Static keyword u.s ass.(2)Static keyword u.s ass.(2)
Static keyword u.s ass.(2)
 
The Ring programming language version 1.6 book - Part 75 of 189
The Ring programming language version 1.6 book - Part 75 of 189The Ring programming language version 1.6 book - Part 75 of 189
The Ring programming language version 1.6 book - Part 75 of 189
 
SQL Joins
SQL JoinsSQL Joins
SQL Joins
 
Test Presentation
Test PresentationTest Presentation
Test Presentation
 
SQL Joins
SQL JoinsSQL Joins
SQL Joins
 
Javascript for the c# developer
Javascript for the c# developerJavascript for the c# developer
Javascript for the c# developer
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 
Java scjp-part1
Java scjp-part1Java scjp-part1
Java scjp-part1
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
 
Java basics
Java basicsJava basics
Java basics
 
Storage Class Specifiers
Storage Class SpecifiersStorage Class Specifiers
Storage Class Specifiers
 
Coding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docxCoding Component (50)Weve provided you with an implementation .docx
Coding Component (50)Weve provided you with an implementation .docx
 
Handout # 4 functions + scopes
Handout # 4   functions + scopes Handout # 4   functions + scopes
Handout # 4 functions + scopes
 

More from JohnLagman3

8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentationJohnLagman3
 
7.-Bootstrap-5-report powerpoint presentation
7.-Bootstrap-5-report powerpoint presentation7.-Bootstrap-5-report powerpoint presentation
7.-Bootstrap-5-report powerpoint presentationJohnLagman3
 
1._Introduction_to_HTML5 powerpoint presentation
1._Introduction_to_HTML5 powerpoint presentation1._Introduction_to_HTML5 powerpoint presentation
1._Introduction_to_HTML5 powerpoint presentationJohnLagman3
 
bufferoverflow-151214121251 presentation
bufferoverflow-151214121251 presentationbufferoverflow-151214121251 presentation
bufferoverflow-151214121251 presentationJohnLagman3
 
Web-Development Powerpoint Presentation.
Web-Development Powerpoint Presentation.Web-Development Powerpoint Presentation.
Web-Development Powerpoint Presentation.JohnLagman3
 
History of Android powerpoint presentation
History of Android powerpoint presentationHistory of Android powerpoint presentation
History of Android powerpoint presentationJohnLagman3
 
Mobile Application Development powerpoint
Mobile Application Development powerpointMobile Application Development powerpoint
Mobile Application Development powerpointJohnLagman3
 
Presentation of Hyper Text Markup Language
Presentation of Hyper Text Markup LanguagePresentation of Hyper Text Markup Language
Presentation of Hyper Text Markup LanguageJohnLagman3
 
html-150424090224-conversion-gate0.2.pdf
html-150424090224-conversion-gate0.2.pdfhtml-150424090224-conversion-gate0.2.pdf
html-150424090224-conversion-gate0.2.pdfJohnLagman3
 
Hypertext Mark Up Language Introduction.
Hypertext Mark Up Language Introduction.Hypertext Mark Up Language Introduction.
Hypertext Mark Up Language Introduction.JohnLagman3
 
Multiple_Linear_Regression Presentation.
Multiple_Linear_Regression Presentation.Multiple_Linear_Regression Presentation.
Multiple_Linear_Regression Presentation.JohnLagman3
 
Lesson 4 - Introduction to Filmora.pptx
Lesson 4 - Introduction to Filmora.pptxLesson 4 - Introduction to Filmora.pptx
Lesson 4 - Introduction to Filmora.pptxJohnLagman3
 
1.-Introduction-report.pdf
1.-Introduction-report.pdf1.-Introduction-report.pdf
1.-Introduction-report.pdfJohnLagman3
 
Lesson 1 Animation.pdf
Lesson 1 Animation.pdfLesson 1 Animation.pdf
Lesson 1 Animation.pdfJohnLagman3
 
Lesson 1.pdf
Lesson 1.pdfLesson 1.pdf
Lesson 1.pdfJohnLagman3
 
Confidentiality Privacy and Security.ppt
Confidentiality Privacy and Security.pptConfidentiality Privacy and Security.ppt
Confidentiality Privacy and Security.pptJohnLagman3
 
physicalsecurity-150317020111-conversion-gate01.pdf
physicalsecurity-150317020111-conversion-gate01.pdfphysicalsecurity-150317020111-conversion-gate01.pdf
physicalsecurity-150317020111-conversion-gate01.pdfJohnLagman3
 
Introduction to BIOMETRICS Security.pptx
Introduction to BIOMETRICS Security.pptxIntroduction to BIOMETRICS Security.pptx
Introduction to BIOMETRICS Security.pptxJohnLagman3
 
1.-Introduction-report.pptx
1.-Introduction-report.pptx1.-Introduction-report.pptx
1.-Introduction-report.pptxJohnLagman3
 
ORIENTATION-CIS.pdf
ORIENTATION-CIS.pdfORIENTATION-CIS.pdf
ORIENTATION-CIS.pdfJohnLagman3
 

More from JohnLagman3 (20)

8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation8.-Javascript-report powerpoint presentation
8.-Javascript-report powerpoint presentation
 
7.-Bootstrap-5-report powerpoint presentation
7.-Bootstrap-5-report powerpoint presentation7.-Bootstrap-5-report powerpoint presentation
7.-Bootstrap-5-report powerpoint presentation
 
1._Introduction_to_HTML5 powerpoint presentation
1._Introduction_to_HTML5 powerpoint presentation1._Introduction_to_HTML5 powerpoint presentation
1._Introduction_to_HTML5 powerpoint presentation
 
bufferoverflow-151214121251 presentation
bufferoverflow-151214121251 presentationbufferoverflow-151214121251 presentation
bufferoverflow-151214121251 presentation
 
Web-Development Powerpoint Presentation.
Web-Development Powerpoint Presentation.Web-Development Powerpoint Presentation.
Web-Development Powerpoint Presentation.
 
History of Android powerpoint presentation
History of Android powerpoint presentationHistory of Android powerpoint presentation
History of Android powerpoint presentation
 
Mobile Application Development powerpoint
Mobile Application Development powerpointMobile Application Development powerpoint
Mobile Application Development powerpoint
 
Presentation of Hyper Text Markup Language
Presentation of Hyper Text Markup LanguagePresentation of Hyper Text Markup Language
Presentation of Hyper Text Markup Language
 
html-150424090224-conversion-gate0.2.pdf
html-150424090224-conversion-gate0.2.pdfhtml-150424090224-conversion-gate0.2.pdf
html-150424090224-conversion-gate0.2.pdf
 
Hypertext Mark Up Language Introduction.
Hypertext Mark Up Language Introduction.Hypertext Mark Up Language Introduction.
Hypertext Mark Up Language Introduction.
 
Multiple_Linear_Regression Presentation.
Multiple_Linear_Regression Presentation.Multiple_Linear_Regression Presentation.
Multiple_Linear_Regression Presentation.
 
Lesson 4 - Introduction to Filmora.pptx
Lesson 4 - Introduction to Filmora.pptxLesson 4 - Introduction to Filmora.pptx
Lesson 4 - Introduction to Filmora.pptx
 
1.-Introduction-report.pdf
1.-Introduction-report.pdf1.-Introduction-report.pdf
1.-Introduction-report.pdf
 
Lesson 1 Animation.pdf
Lesson 1 Animation.pdfLesson 1 Animation.pdf
Lesson 1 Animation.pdf
 
Lesson 1.pdf
Lesson 1.pdfLesson 1.pdf
Lesson 1.pdf
 
Confidentiality Privacy and Security.ppt
Confidentiality Privacy and Security.pptConfidentiality Privacy and Security.ppt
Confidentiality Privacy and Security.ppt
 
physicalsecurity-150317020111-conversion-gate01.pdf
physicalsecurity-150317020111-conversion-gate01.pdfphysicalsecurity-150317020111-conversion-gate01.pdf
physicalsecurity-150317020111-conversion-gate01.pdf
 
Introduction to BIOMETRICS Security.pptx
Introduction to BIOMETRICS Security.pptxIntroduction to BIOMETRICS Security.pptx
Introduction to BIOMETRICS Security.pptx
 
1.-Introduction-report.pptx
1.-Introduction-report.pptx1.-Introduction-report.pptx
1.-Introduction-report.pptx
 
ORIENTATION-CIS.pdf
ORIENTATION-CIS.pdfORIENTATION-CIS.pdf
ORIENTATION-CIS.pdf
 

Recently uploaded

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxabhijeetpadhi001
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 

Recently uploaded (20)

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAĐĄY_INDEX-DM_23-1-final-eng.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
MICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptxMICROBIOLOGY biochemical test detailed.pptx
MICROBIOLOGY biochemical test detailed.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 

Variables in MIT App Inventor powerpoint

  • 1. Variables in MIT App Inventor Global Variable and Local Variable
  • 2. What is Global Variable?  A global variable is a variable that can be accessed in multiple scopes. This means that wherever you are in the program you can use that variable; get its current value or set its value to something else. Global variables are created using the initialize global name to block found in the Variables drawer.
  • 3. What is Local Variable?  A local variable is a variable that is declared within a function or it is an argument passed into a function. This means that you can only access these variables in that specific function where they are declared or passed in as an argument.
  • 4. Variables Overview  The Variables drawer provides blocks to create, get, and set both global and local variables. Explanations of all of the blocks available in this drawer can be found on the Variables page.
  • 5. There are five main types of variable blocks:
  • 6. ‱ initialize global name to ‱ get ‱ set ‱ initialize local name to in (do) ‱ initialize local name to in (return)
  • 7. “initialize global name to” This block is used to create global variables. It takes in any type of value as an argument. Clicking on name will change the name of this global variable. Global variables are used in all procedures or events so this block will stand alone. Global variables can be changed while an app is running and can be referred to and changed from any part of the app even within procedures and event handlers. You can rename this block at any time and any associated blocks referring to the old name will be updated automatically.
  • 8. “get” This block provides a way to get any variables you may have created.
  • 9. “set” This block follows the same rules as “get”. Only variables in scope will be available in the dropdown. Once a variable v is selected, you can attach a block to give v a new value.
  • 10. “initialize local name to - in (do)”  This block is a mutator that allows you to create new variables that are only used in the procedure you run in the DO part of the block. This way all variables in this procedure will all start with the same value each time the procedure is run. NOTE: This block differs from the block described below because it is a DO block. You can attach statements to it. Statements do things. That is why this block has space inside for statement blocks to be attached.  You can rename the variables in this block at any time and any corresponding blocks elsewhere in your program that refer to the old name will be updated automatically
  • 11. “initialize local name to - in (return)”  This block is a mutator that allows you to create new variables that are only used in the procedure you run in the RETURN part of the block. This way all variables in this procedure will all start with the same value each time the procedure is run. NOTE: This block differs from the block described above because it is a RETURN block. You can attach expressions to it. Expressions return a value. That is why this block has a socket for plugging in expressions.  You can rename the variables in this block at any time and any corresponding blocks elsewhere in your program that refer to the old name will be updated automatically
  • 12. Global Variable Example Take out a get block and click the dropdown. There will be no variables to select. Create a global variable and name it count and initialize it to 0. Click on the dropdown of the get block. You can now see count available to choose. Once you have created a global variable, it will always be available in the dropdown of get .
  • 13. Local Variable Example Create a local variable using initialize local name to in do block and name it a. Now drag out a set block and put it outside of the initialize local name to in do block. Click on the dropdown of the set block. You will not see a as a choice in the dropdown. This is because the set block is out of the scope of the local variable's domain. Move the block inside of the do part of the initialize local name to in do block. Click the dropdown of the set block. Now a is available to choose.
  • 14. Variable Labels  Notice how when you use a get or set block for a global variable. The block will say global name.  When using get or set blocks for local variables, the block will only say name. Remember that local variables include variables created from arguments to procedures or event handlers, variables created for use in for loops, or initializing local variables for an expression or return statement by using the orange local variable initialize blocks.
  • 15. Why would I ever need to use local variables? Sometimes you may need to create a new variable within a procedure and only want that procedure to be able to use it. In this example, we use a local variable, height, to store the height of the triangle whose hypotenuse and base we're given as arguments. We might have a different procedure that uses height as an argument so we would not be able to use a global variable. To make sure of that, we use local variables so that the height in the right context is only available in the procedure where it is used. Sometimes it might just be easier to have local variables rather than creating many new global ones. Or it might allow us to use less blocks.
  • 16. MIT App Inventor Control Blocks (Loops and Conditions)
  • 17. “if & else if” Tests a given condition. If the condition is true, performs the actions in a given sequence of blocks; otherwise, the blocks are ignored. Tests a given condition. If the condition is true, performs the actions in the -then sequence of blocks; otherwise, performs the actions in the -else sequence of blocks. Tests a given condition. If the result is true, performs the actions in the -then sequence of blocks; otherwise tests the statement in the -else if section. If the result is true, performs the actions in the -then sequence of blocks; otherwise, performs the actions in the -else sequence of blocks.
  • 18. “for each number from to” Runs the blocks in the do section for each numeric value in the range starting from from and ending at to, incrementing number by the value of by each time. Use the given variable name, number, to refer to the current value. You can change the name number to something else if you wish.
  • 19. “for each item in list” Runs the blocks in the do section for each item in the list. Use the given variable name, item, to refer to the current list item. You can change the name item to something else if you wish.
  • 20. “for each key with value in dictionary” Runs the blocks in the do section for each key-value entry in the dictionary. Use the given variables, key and value, to refer to the key and value of the current dictionary entry. You can change the names key and value to something else if you wish.
  • 21. “while” Tests the -test condition. If true, performs the action given in -do , then tests again. When test is false, the block ends and the action given in -do is no longer performed. if then else Tests a given condition. If the statement is true, performs the actions in the then-return sequence of blocks and returns the then- return value; otherwise, performs the actions in the else-return sequence of blocks and returns the else-return value. This block is similar to the ternary operator (?:) found in some languages.
  • 22. “do with result” Sometimes in a procedure or another block of code, you may need to do something and return something, but for various reasons you may choose to use this block instead of creating a new procedure.
  • 23. “evaluate but ignore result” Provides a “dummy socket” for fitting a block that has a plug on its left into a place where there is no socket, such as one of the sequence of blocks in the do part of a procedure or an if block. The block you fit in will be run, but its returned result will be ignored. This can be useful if you define a procedure that returns a result, but want to call it in a context that does not accept a result.
  • 24. open another screen Opens the screen with the provided name. The screenName must be one of the Screens created using the Designer. The screenName should be selected from the connected screen name dropdown block. If you do open another screen, you should close it when returning to your main screen to free system memory. Failure to close a screen upon leaving it will eventually lead to memory problems. App developers should never close Screen1 or use this block to return to Screen1. Use the close screen block instead.
  • 25. open another screen with start value Opens another screen and passes a value to it.
  • 26. get plain start text get start value Returns the plain text that was passed to this screen when it was started by another app. If no value was passed, it returns the empty text. For multiple screen apps, use get start value rather than get plain start text. Returns the start value given to the current screen. This value is given from using open another screen with start value or close screen with value.
  • 27. close screen close screen with plain text close screen with value close application Closes the current screen. Closes the current screen and passes text to the app that opened this one. This command is for returning text to non-App Inventor activities, not to App Inventor screens. For App Inventor Screens, as in multiple screen apps, use close screen with value, not close screen with plain text. Closes the current screen and returns a value to the screen that opened this one. Closes the application.
  • 28. break When looping using the for range, for each, or while blocks it is sometimes useful to be able to exit the loop early. The break allows you to escape the loop. When executed, this will exit the loop and continue the app with the statements that occur after the loop in the blocks.