04ConditionalStatements

04ConditionalStatements - CSE 114 Computer Science I...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 114 Computer Science I Conditional Statements Quirpon Island, Newfoundland Take two data values of the same type Returns a boolean result ( true or false ) < (less than) > (greater than) <= (less than or equal to) >= (greater than or equal to) == (equal to) != (not equal to) Examples: Relational Operators // result is true // result is true // result is false result = (5 <= 9); result = (3.9 > 3.19); result = (a == A); boolean result; We will use these to build boolean expressions Logical Operators Two data values of type boolean Return a boolean result (true or false) && (logical AND) , & (bitwise AND) || (logical OR) , | (bitwise OR) // result is false // result is true // result is false result = (5<=9 && 8>9); result = (5<=9 || 8>9); boolean result; result = !(5<=9); Unary logical operator: ! (NOT) We will not use these operators Fully Parenthesize your Expressions What is the value of result after the assignment expression: boolean result; result = 5+x<7&&y/z==0; // confusing Answer: I dont care because I would never write it that way result = ( ( (5+x)<7 ) && ((y/z)==0) ); // better The ifelse ifelse statement Used for program decision making if would test for first choice else if s would test for additional choices not required else would be for all other cases not required Can you think of any decisions a program makes? How do we use it?...
View Full Document

Page1 / 20

04ConditionalStatements - CSE 114 Computer Science I...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online