Programming Your App to Make Decisions – Conditional Blocks

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Understanding an Apps Architecture ASFA Computer Science: Principles Fall 2013.
CS0007: Introduction to Computer Programming
 Control structures  Algorithm & flowchart  If statements  While statements.
靜宜大學資管系 楊子青 1 Programming Your App’s Memory 靜宜大學資管系 楊子青
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Introduction to Computers and Programming Lecture 5 New York University.
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
Visual C++ Programming: Concepts and Projects
CS 106 Introduction to Computer Science I 09 / 28 / 2007 Instructor: Michael Eckmann.
TECH19599 Exploring Information Technology Mobile Application Development (Control Statements)
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design First Edition by Tony Gaddis.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
Module 3: Steering&Arrays #1 2000/01Scientific Computing in OOCourse code 3C59 Module 3: Algorithm steering elements If, elseif, else Switch and enumerated.
Conditional Structures UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Summer Computing Workshop. Session 3 Conditional Branching  Conditional branching is used to alter the normal flow of execution depending on the value.
SOFTWARE TESTING. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves any activity.
CPS120: Introduction to Computer Science Decision Making in Programs.
Copyright ©2005  Department of Computer & Information Science If-Then-Else Structures.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
Control Structures: Conditionals, If/Else and Loops David Millard
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Introduction to Programming and App Inventor. Introduction What is a computer program? Introducing App Inventor Getting hands on with App Inventor.
CHAPTER 4 DECISIONS & LOOPS
CS0007: Introduction to Computer Programming
Chapter 4: Making Decisions.
Statements (6 of 6) A statement causes an action to be performed by the program. It translates directly into one or more executable computer instructions.
Chapter 4: Making Decisions.
Engineering and Debugging an App Chapter 15
Selection—Making Decisions
CS1371 Introduction to Computing for Engineers
Understanding an App’s Architecture
Topics The if Statement The if-else Statement Comparing Strings
If, else, elif.
The order in which statements are executed is called the flow of control. Most of the time, a running program starts at the first programming statement,
Chapter 4: Decision Structures and Boolean Logic
Structural testing, Path Testing
Repetition Structures (Loops)
Programming Fundamentals
Chapter 16 – Programming your App’s Memory
Microsoft Visual Basic 2005 BASICS
Selection By Ramin && Taimoor
Lecture 2: Logical Problems with Choices
Understanding an App’s Architecture
Lesson 8: Boolean Expressions and "if" Statements
IF if (condition) { Process… }
CS320n –Visual Programming
Computers & Programming Languages
Lesson 1: Fundamentals of Programming
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
Chapter 4: Decision Structures and Boolean Logic
Introduction to Problem Solving and Control Statements
Chapter 5: Control Structure
Conditional Logic Presentation Name Course Name
15-110: Principles of Computing
Introduction to AppInventor
Programming Lists of Data 靜宜大學資管系 楊子青
CHAPTER 4: Conditional Structures
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Chapter 4: Decision Structures and Boolean Logic
Exception Handling.
Decision Statements.
Control Structures.
Presentation transcript:

Programming Your App to Make Decisions – Conditional Blocks App Inventor – Chapter 18 Programming Your App to Make Decisions – Conditional Blocks

From Chapter 18 Introduction Computers, even small ones like the phone in your pocket, are good at performing thousands of operations in just a few seconds. Even more impressively, they can also make decisions based on the data in their memory banks and logic specified by the programmer. This decision-making capability is probably the key ingredient of what people think of as artificial intelligence, and it’s definitely a very important part of creating smart, interesting apps! In this chapter, we’ll explore how to build decision-making logic into your apps.

Decisions, decisions, decisions . . . Computer code (no matter the language) executes these three ways: Sequentially Using conditional logic Repetitively The ‘normal’ assumption with code is that it executes sequentially Here we explore decisions . . . In most languages, there are two ways to express conditional logic: if-then-else (practically all languages) switch (C++, Java) or Select-Case (Visual Basic)

Look at this event handler: When Event1 is triggered, block A is executed Then some kind of condition is tested If true, block B1 is executed (B1 ‘branch’). If not, block B2 is executed (B2 ‘branch’). Block C is executed either way What are the possible paths through the code?

if and if-else blocks in App Inventor

‘if’ and ‘if-else’ are used with ‘relational operator’ and/or ‘logical operator’ blocks: Relational Operators Logical Operators These get plugged into the test blocks of ‘if’ and ‘if-else’ blocks

Example of ‘if-then’: What happens if ‘score’ is greater than 100? What happens if ‘score’ is less than 100? What happens if ‘score’ is exactly equal to 100?

Programming an either/or situation

Conditions within conditions

Complex conditions Example: Is your phone somewhere inside the Harney Science Center at University of San Francisco? Is the phone’s latitude less than the maximum latitude (37.78034) of the boundary? Is the phone’s longitude less than the maximum longitude (–122.45027) of the boundary? Is the phone’s latitude more than the minimum latitude (37.78016) of the boundary? Is the phone’s longitude more than the minimum longitude (–122.45059) of the boundary?

Here are the blocks you’ll need:

Here are the blocks you’ll need:

But we can handle even more complexity . . . Suppose you wanted the phone to vibrate only when the boundary was crossed from inside to outside . . . You’ll need one of these:

There’s a lot of subtle stuff going on here. Check it out carefully.

Same or different?

Summary Is your head spinning? That last behavior was quite complex! But it’s the type of decision making that sophisticated apps need to perform. If you build such behaviors part by part (or branch by branch) and test as you go, you’ll find that specifying complex logic--even, dare we say, artificial intelligence--is doable. It will make your head hurt and exercise the logical side of your brain quite a bit, but it can also be lots of fun.