1 / 11

Programming with App Inventor

Programming with App Inventor. Computing Institute for K-12 Teachers Summer 2012 Workshop. Advanced Boolean Expressions and Lists Session SA-5. Boolean Review Boolean Logic Operators.

monet
Download Presentation

Programming with App Inventor

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop

  2. Advanced Boolean Expressionsand ListsSession SA-5

  3. Boolean ReviewBoolean Logic Operators • The App Inventor provides for several implementations of Boolean expression shown below. The are found under the Built-In Logic section in the BlocksEditor, in the Math and Logic drawers. There are some Text comparison operators under the Text section as well. • A Boolean variable must have a value of either or . • You can negate , or , or and Boolean variables. • You create a Boolean variable as you would any normal variable but you must set the variable’s value to either the true object, the false object ( , ) or the result of a Boolean expression. • The operands for the Boolean operators (not , and , or) must use a Boolean value (true, false, a Boolean variable, or a Boolean expression). • The Boolean and ( ) will compare a series of Boolean values (true, false, or Boolean variables. • This sample show the use of the and operator comparing two Boolean variables. The and operator return true if all the ‘test’ are true. The test is done from top to bottom until the a false value is encountered at which time a false value will be returned. • But no matter how you combine them, Boolean expressions evaluate to either True or False.

  4. Boolean ReviewBoolean Logic Operators • The or operator compares a series of Boolean values or Boolean expressions until a true result is found. At that time the or block will return a true value. A false value will only be return if all the comparison are false. • Boolean Expressions are calculations that evaluate to either True or False. The comparisonblock returns a Boolean result. The variables ‘a’ and ‘b’ represent any expression that return a result that can be used by the comparison operators. • The comparison operator block can be found in Built-In tab of BlocksEditor under the Logic and MathSections as well. • If you need to compare text strings use the ‘text=‘ comparison block show below. The comparison operators for strings are in the Built-InDefinition under the Text section.

  5. Lists • Lists (also known as Arrays) are an essential programming tool. Lists can store multiple values (called elements) that the programmer may need later in their program. Creating a List, in a way, is like creating multiple variables. For example, if we were to have a List of length 5. That means we have 5 separate values held within the List. • Each value in the List is indexed by a number. With the App Inventor, indices begin at 1, so the first element is indexed with the number 1 and the second element is indexed with the number 2. Indexing is the way we keep track of where a specific value is located in the List. • The length of a List needs is determined by the number of value added to the List. There many routine available in the Built-In Tab of the Blocks Editor under the Lists section (or drawer). • For example, is the length of list function which will return the number of items in the given List.

  6. Creating an List • Creating an List is similar to creating a variable. Use the Blocks Editor Built-In Definitions to create a variable. • Once you have created the variable you can assign its initial value to the function makealist. The List functions are found in the Built-In tab under the Lists section in the Blocks Editor. • The blocks below show a variable created from the Built-InDefinitions, renamed to numList and then assigned to an initial value from the function call make a list, thus making an empty List that can be later populated with items in you program.

  7. Lists • The are many functions that can be used with a List. The graphic below shows the predefined blocks used to work with Lists. These are located in the Blocks Editor Built-InTab under the Lists section.

  8. Lists • The follow block show an simple example of adding items to a List. • The for range loop cycles from 1 to 10.The index variable ‘i’ increments by 1 increasing from 1 to 10 with each iteration. • Each value of ‘i’ (1 to 10) will be addedas an item in the List named numList.When the for loop exits, numList will have 10 items with the value of 1 through 10. The first item will have avalue of 1, the 2nd item will a value of 2 and so on. • Although, this example has all the items in the list as a number, List items may be of any type.

  9. Project 6 • Following the samples example, create your own quiz with a few differences. Add an image for each question you ask, and have one of the questions have multiple answers.

  10. Day 3 Questions • In the Blocks Editor, how (or where) do you define a procedure? (Hint: same place you define a variable). • You have a program that has an If/Else structure, and two variables, A and B. The only time you want the alternate part of the If/Else structure to execute is when both variables equal 10. What Boolean expression could you use in this situation? • What are the two types of procedure calls in App Inventor? What is the difference? • Can an argument be used with both types of Procedures (___yes/­___ no)?   • What structure in App Inventor could you use to store a series of items? • Name  two control blocks that can be used in the App Inventor? • What block is used to define an argument passed into a procedure?

  11. Day 3 – Answer Key • In the Blocks Editor, how (or where) do you define a procedure? (Hint: same place you define a variable).In the Blocks Editor from the Definitions section (drawer) • You have a program that has an If/Else structure, and two variables, A and B. The only time you want the alternate part of the If/Else structure to execute is when both variables equal 10. What Boolean expression could you use in this situation?(not ((A = 10 ) and (B = 10))) • What are the two types of procedure calls in App Inventor? What is the difference?One that returns a value and one that does not. • Can an argument be used with both types of Procedures (_X__yes/­___ no)?   • What structure in App Inventor could you use to store a series of items?a List object • Name  two control blocks that can be used in the App Inventor?if, ifelse, foreach loop , for range loop , while loop • What block is used to define an argument passed into a procedure?the named argument object , created from the Built-In Definitions in the Blocks Editor

More Related