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

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

Chapter 4 - Control Statements
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Decision Structures Chapter 4. Chapter 4 Objectives To understand: o What values can be stored in a Boolean variable o What sequence structures are and.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Selection (decision) control structure Learning objective
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
School of Computing Science CMT1000 Ed Currie © Middlesex University 1 CMT1000: Introduction to Programming Ed Currie Lecture 5B: Branch Statements - Making.
Thirteen conditional expressions: letting programs make “decisions”
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Chapter 4: Control Structures: Selection
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
CPS120: Introduction to Computer Science Decision Making in Programs.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
Summer Computing Workshop. Introduction  Boolean Expressions – In programming, a Boolean expression is an expression that is either true or false. In.
MS3304: Week 6 Conditional statements. Overview The flow of control through a script Boolean Logic Conditional & logical operators Basic decision making.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
© Jalal Kawash Programming Peeking into Computer Science 1.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
 Learn about control structures  Examine relational and logical operators  Explore how to form and evaluate logical (Boolean) expressions  Learn how.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Lecture 3 – Selection. Outline Recall selection control structure Types of selection One-way selection Two-way selection Multi-selection Compound statement.
Conditional Structures UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Lesson - 5. Introduction While programming, we usually need to decide the path of the program flow according to the parameters and conditions. Actually.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
BACS 287 Programming Logic 2. BACS 287 Sequence Construct The sequence construct is the default execution mode for the CPU. The instructions are executed.
MIT App Inventor Lesson 4 – Decision Making. Agenda Comparisons ◦ Relational Operators Conditions (state checking) ◦ Boolean Operators.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 If’s – The Basic Idea “Program” for hubby: take out garbage.
Summer Computing Workshop. Session 3 Conditional Branching  Conditional branching is used to alter the normal flow of execution depending on the value.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
Basic Conditions. Challenge: ● Ask the user his/her name ● If it’s “Wally,” jeer him ● Pause video and try on your own.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
CPS120: Introduction to Computer Science Decision Making in Programs.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Using Control Structures. Goals Understand the three basic forms of control structures Understand how to create and manage conditionals Understand how.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
CPS120: Introduction to Computer Science Decision Making in Programs.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
ME 142 Engineering Computation I Condition Statements.
Computer Science Up Down Controls, Decisions and Random Numbers.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Making Choices with if Statements
Chapter 3: Decisions and Loops
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Javascript Conditionals.
Microsoft Visual Basic 2005 BASICS
Introduction To Robot Decision Making
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Selection Statements.
Chapter 4: Control Structures I (Selection)
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Relational Operators.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Presentation transcript:

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

Conditional Branching - Booleans Session SA-2

Conditional Branching We encounter situations that employ conditional branching techniques every day. It all comes down to choices. We often have two or more things to do at a time and must decide upon one and only one. When faced with choices such as these, we must evaluate the reasoning for each and make a decision based on a condition. For example, say you bring $300 to the mall to buy a new outfit. You narrow it down to two selections; the first costs $500, but the second costs $200 and isn’t as nice. You think to yourself “If I have more than $500 I will buy the nicer outfit. Otherwise, I will buy the other outfit.” This is a perfect example of a conditional branching.

Conditional Branching Conditional branching is used to alter the normal flow of execution depending on the value of a Boolean expression (Boolean expressions are explained in the following slide). The use of conditional branching allows programs to become much more flexible. The primary block associated with this behavior is the if/then-do block or the ifelse/then-do/else-do block The test “If” or “ifelse is called the predicate or conditional part of the structure and is where the Boolean expression is placed. This is what determines if the consequent (internal), or alternate (else) blocks are executed.

Boolean Expressions If blocks are controlled by Boolean expressions located in the predicate area. The ‘test’ component will evaluate to either true or false. By default, the if block is created with an empty test. The test must be set to True, False, a Boolean variable or a Boolean expression. It can also be set to a procedure that returns a Boolean result (True or False). The Boolean Logic operators for Boolean expressions are found in the Built-In Logic in the Blocks Editor. If the expression in the predicate evaluates to “True,” the blocks located below “If” ARE executed, and the blocks located below “Else” are NOT executed. Conversely, if the expression evaluates to “False”, the blocks located below “If” are NOT executed, and the blocks located below “Else” ARE executed. ‘=‘ can be replaced with these operator

Conditional Branching – If/Else Block Let’s take a look at an example: This if/then-do/else-do block compares two numbers using the ‘=‘ operator (compares the number 1 to itself). In the example above, 1 does equal 1 and the test evaluation is true. Since the ‘test’ is true, the “then-do” branch will be executed (set the text of a Label to ‘This is true’). The branch ‘else-do’ will not be executed.

Conditional Branching – If/Else Block Let’s take a look at an the same example that evaluates false: This if/then/else block compares two numbers (asks if 1 is greater than itself). In the example above, 1 is not greater than 1 and the test evaluation is false. Since the ‘test’ is false, the “then-do” branch will not be be executed. The branch ‘else-do’ will be executed, setting the label text to ‘This is false’

Conditional Branching – If/Else Block In many cases, the if/then/else blocks compare two variables whose value are set by your program and/or user input. It is important to keep track of what is being compared. The App Inventor will allow comparisons of different types of data if they are compatible but will raise an error condition if they are not.

Conditional Branching – Nesting The if/then/else decision making can be nested, several comparisons maybe needed in your program to obtain the desired result and can be nested several layers deep. These nested if/then/else blocks determine if two variables are equal, greater or less than one another and set the label text accordingly.

Sample 2 Conditional Branching Coin Flip

Project 2 Conditional Branching Ask a question of the user and have them input the answer into a textbox, then tell the user if the answer was correct or not.