Presentation is loading. Please wait.

Presentation is loading. Please wait.

MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.

Similar presentations


Presentation on theme: "MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators."— Presentation transcript:

1 MIT App Inventor Lesson 4 – Decision Making

2 Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators

3 Agenda Conditionals / Control Structures ◦ if ◦ if else ◦ if elif else Boolean Operators ◦ NOT ◦ AND ◦ OR

4 Motivation People make decisions often. Programs need information and conditions to make decisions.

5 How do we make decisions? We Use Information QualitativeQuantitative Raining?5 degrees Celsius Type of Information FeatureQuantity

6 Quantitative Decisions? Scenario Compare values to help determine which code to execute next within the program. CS Concept Relational Operators ◦ Used to compare values (operands)

7 AI – Relational Operators Location Math block group Example. When a student obtains a mark between 50% and 100% (inclusive) they will be granted a credit for the course.

8 AI – Relational Operators Located within the Math block group Operator Comparison Description Greater than Greater than or Equal to Less than Less than or Equal to Equal to Not Equal to

9 Relational Operator Examples

10 Controlling Program Flow How can a user control program flow? ◦ Buttons

11 Controlling Program Flow How can a programmer control program flow? ◦ Order of block/code in the design (blocks editor) will determine the order of execution  Sequential – Top to bottom in order ◦ Others?  Procedures – Named group of blocks / Called by the programmer

12 Programming Fundamentals Software programs consist of 3 key components: ◦ Data Structures  Variables – named storage areas (more later) ◦ Control Structures  Decision making (this lesson) ◦ Algorithms  combinations of Data and Control Structures to solve a specific well-defined program

13 Take Control with Control Structures Located within the Control block group Conditional Block ◦ condition (test) ◦ set of statements to be executed when the condition is true.

14 Simple Condition - Example Scenario involves checking one criteria and there is only an unique action to be taken if the criteria is met (otherwise true). Example: Voting Condition

15 Handling Two Outcomes Scenario Single Criteria with two Outcomes Problem Domain Completing your in-car driving test with a goal of obtaining your drivers license. Only 2 possible outcomes 1.Pass 2.Fail

16 Getting Your License

17 Qualitative Decisions? Scenario Check states to help determine which code to execute next within the program. CS Concept Boolean Operators ◦ Used to compare states (operands)

18 Boolean Operators Any question that can be answered Yes or No is considered a boolean condition. Interesting Fact Boolean logic was initially described by George Boole (1815-1864). This was long before the existence of the first digital computers.

19 Example: Boolean and Relational Example. If it is raining outside and it is between 5  C and 10  C I will wear my warm rain jacket and take the bus. Multiple conditions must be met.

20 AI – Boolean Operators Located within the Math block group Operator Comparison Description All tests must be true for result to be true If any of the tests are true the result is true. The result is the opposite of the input.

21 Complex Example

22 Lab 4 – Temp Convertor Objective Create a temperature convertor program for Fahrenheit and Celsius. ◦ Components  Button  TextBox  Screen Arrangement ◦ Concepts  Math operators  Conditions  If test  then-do  Ifelse test  then-do  else-do ◦ Algorithms  see lab instructions

23 Example from the next Lab


Download ppt "MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators."

Similar presentations


Ads by Google