Download presentation
Presentation is loading. Please wait.
Published byAlannah O’Brien’ Modified over 9 years ago
1
Decision Structures Chapter 4 Part 2
2
Chapter 4 Objectives To understand o What relational operators are and how they are used o Boolean logic o Testing the value of an object’s property 4-2
3
Relational Comparisons Relational Operators are used to compare values and determine whether relationships exist o Greater than o Less than o Equal to Compare two values and determine how they relate to each other OperatorMeaning = Equal to ! =Not equal to >Greater than > =Greater than or equal to <Less than < =Less than or equal to 4-3
4
Relational Operators Used to write your own comparison o In If/Else and other tests Operates on two pieces of data o a and b Alice uses “a” and “b” for placeholders o Drag the desired tile and replace either the “a” or “b” with a value 4-4
5
Concept Illustrated Relational operations are defined using relational operators 4-5
6
Boolean Logic Can check for multiple conditions at one time with Boolean logic instead of nesting If/else statements Boolean logic operators are used to build an expression composed of multiple conditions o And Boolean: A and B: True only when both are true In Alice: Both A and B o Or Boolean: A or B: True when one or both are true In Alice: Either A or B, or both o Not Inverses what is sent to it Example: if A = True then not A is False In Alice: not A 4-6
7
Boolean Logic in Functions Choose World object Then choose functions o Select desired Boolean function o Drag to conditional instruction like If/Else Condition 4-7
8
Logical Operators Tests more than true/false Can do complex testing Test two conditions to see if o They BOTH are true (and) o ONLY one condition is true (or) o NEITHER condition is true (not) 4-8
9
Example Can combine multiple conditions Example: Condition is true if o The penguin is within 2 meters o And the circle is wider than the penguin Similar to nested If/Else but doesn’t do contents of second Else statement o Penquin says “Drats“ 4-9
10
Testing Value of Object’s Property Sometimes you might want to see what a property of an object is o Color o Opacity o isShowing 4-10
11
How to Testing Object’s Property Create an empty If/Else instruction Select object to test Click properties tab Drag desired property’s tile and drop onto If/Else instruction’s condition Menu appears showing all comparisons to perform o Select desired comparison Another menu appears allowing you to select value that you want to compare property to o Ex: color property will give list of colors 4-11
12
Example Algorithm Frog and ladybug are in garden 4-12 Ladybug says “Excuse me” Frog turns to face ladybug If ladybug’s color is red Frog says “EEK! Go away!” Else Frog says “Good Morning” Endif
13
Property Test Demonstration 4-13
14
Homework Read chapter 4.4 Do lab assignments Answer questions in handout Due one week after assigned with 1 week grace 4-14
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.