110 likes | 221 Vues
This document outlines the essentials of Boolean expressions, relational operators, and conditional statements, crucial for programming. Key topics include the use of AND, OR, and NOT operators to evaluate conditions, alongside practical examples to illustrate these concepts. Understanding if and if-else statements empowers students to create logic-driven applications. Assignments and reading materials are also specified, urging students to submit their lab works and final project ideas. Adhering to deadlines is vital for receiving credit.
E N D
Introduction to Logic and Conditional Block Dr. José M. Reyes Álamo
Pending Items • Post the following Labs into your OpenLab portfolio ASAP: • Android Zoo App • PaintPot • I started grading and most of you don’t have them. You must post them by midnight to get credit before I do my final round of grading. • Post you final project idea into your OpenLab portfolio with the following information: • App you are planning to develop • Your team member • Even though you will work in groups, portfolios will be graded individually.
Outline • Boolean expressions • Relational operators • If and Ifelse statement
AND operators (&) = All statements must be TRUE for the operation to be TRUE. AND operator STATEMENT 1 AND STATEMENT 2 TRUE TRUE & TRUE • Example: • Check if the following operation is TRUE or FALSE • X>10 & Y<=-4 • If X = 11 and Y = 1 • 11>10 & 1<=- 4 • If X=20 and Y -10 • 20>10 & -10<=-4 TRUE AND FALSE FALSE TRUE AND TRUE TRUE
OR operator • OR operators (|) = At least one statement must be TRUE for the operation to be TRUE. STATEMENT 1 OR STATEMENT 2 TRUE FALSE || TRUE FALSE FALSE || FALSE • Example: • Check if the following operation is TRUE or FALSE • X>10 || Y<=-4 • If X = 11 and Y = 1 • 11>10 || 1<=- 4 • If X=2 and Y =2 • 2 >10 || 2<=- 4 TRUE OR FALSE TRUE FALSE OR FALSE FALSE
NOT operator • NOT operator (!, ~) = Inverts the Boolean value of a variable or expression. NOT STATEMENT 1 ! TRUE = FALSE ! FALSE = TRUE !(11>10)= FALSE
If and ifelse statement Test statement If test statement is TRUE, then do the following.. If test statement is TRUE, then do the following… If test statement is FALSE, then do the following… If test statement is FALSE, skip the if statement
Algorithm – Pseudo Code // Use if statement to check the default size. defaultSize = 5; smallSize = 3; bigSize = 8; If defaultSize<8 &&defaultSize>3 Display in LabelResult = The dot size is set to default; end
ASSIGNMENTS • Idea for final project due TODAY • IN CLASS LAB: • LAB9 QuizMe • READING ASSIGNMENTS: • AppInventor CH20 (Repeating Blocks) • AppInventor CH22 (Working with Databases) • READING ASSIGNMENT EVALUATION: • Complete the reading assignments (2 CHAPTERS) and answer the RA10_AppInventorCh20andCh22 on Blackboard. • First draft for final project due NEXT WEEK.