Lecture 4 Flashcards
Conditions, Logical Expressions and Selection
What is a condition?
A logical expression which are either true or false
E.g.
if condition is true then
execute block1
else condition is false then
execute block2
OR
while condition is true
Repeat executing block1
What is combined to make a condition?
- Relational Operators
- Logical Operators
- Other variables, constants, literals,..
What are relational operators?
< less than
<= less than or equal
> greater than
>= greater than or equal
== identically equal to
!= not equal to
What is a branch?
An if statement
What is a one way branch?
if
What is a two way branch?
if-else
What is a multi-way branch?
if-else if-else
What is used to store true or false values?
bool
What does ! represent?
Is the NOT operator it is unary, the reversing of the value of a logical expression
What are combine conditions?
- && - AND
- || - OR
- ! - NOT
What is &&?
A binary boolean operator, both operands have to be true for the result to be true
What is ||?
A binary boolean operator, at least one of the operands have to be true for the result to be true
(What is !) ?
A unary boolean operator, if the operand is true the result is false