# 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
β 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.

## 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

\$8 USD/m\$10 USD/m
Billed \$96 USD annually
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class