CS 0007 Lecture Notes - Lecture 5: Boolean Expression, Ampersand

26 views2 pages
10 Oct 2017
School
Course
Decision Structures
Rules that allow for a program to have multiple laths of execution
Common to all programming languages
Rules follow the way we think about different scenarios
If a student is a freshman, schedule for new student orientation
If a s student is a freshman, schedule for new student orientation. Else if
a student is a senior, welcome them and remind them of graduation
requirements paperwork. Else send a welcome back message
“If” Decision Structure
Conditional execution based on a boolean expression
A boolean expression is an expression that evaluates to true or false
Result of method calls
Result of relational operators
If (expression)
statement
If (expression)
{
statement 1
statement 2
}
If the expression’s conditions are not met, the program will jump to the end of the
block
Can have many else ifs, but only one else
You can nest if statements within each other
Double ampersand means true, otherwise one is false ?
Relational Operators
X and Y are primitive types (int, byte, double..)
For objects, use equals or compareTo
<, >, <=, >=, ==
Logical Operators
Join two or more relational operations into a single operation (see truth tables in
powerpoint)
Logical, relational and arithmetic operation have a complex precedence structure
&&: The only time something is true, is when both conditions are true, otherwise the
result is false
&& = AND
|| = OR (see example below, opposite of ampersand)
! = NOT
When you have a complex expression, it will do the arithmetic operations first, then relational
operators, THEN logical operators.
3+5 < 7 || 8-2 >= 5
8 < 7 || 6 >= 5
false || true
true
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 2 pages and 3 million more documents.

Already have an account? Log in

Document Summary

Rules that allow for a program to have multiple laths of execution. Rules follow the way we think about different scenarios. If a student is a freshman, schedule for new student orientation. If a s student is a freshman, schedule for new student orientation. Else if a student is a senior, welcome them and remind them of graduation requirements paperwork. Conditional execution based on a boolean expression. A boolean expression is an expression that evaluates to true or false. If the expression"s conditions are not met, the program will jump to the end of the block. Can have many else ifs, but only one else. You can nest if statements within each other. X and y are primitive types (int, byte, double) Join two or more relational operations into a single operation (see truth tables in powerpoint) Logical, relational and arithmetic operation have a complex precedence structure.

Get access

Grade+20% OFF
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers