04ConditionalStatements

# 04ConditionalStatements - CSE 114 – Computer Science I...

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

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

View Full Document

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

View Full Document

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

View Full Document
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 don’t care because I would never write it that way result = ( ( (5+x)<7 ) && ((y/z)==0) ); // better The if…else if…else 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

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online