# Scala – IF ELSE Statements

In Scala IF ELSE can be used in two ways, as statements and as expressions.

General form of an if-else statement:

When we use if as statements, we evaluate a Boolean expression and based on the result of the Boolean expression the code executes a statement. In this case the statement does not return anything by default.

General form of an if-else expressions:

When we use if as expression, we evaluate a Boolean expression and based on the result of the Boolean expression the code executes a statement. But in this case the if expression return the result of if expression.

Example:

Logical Operators

• Scala provides logical operators.
• The binary logical operators combine two boolean expressions into one.
• The unary logical operator switches the value of a boolean expression.
• Binary logical operators have lower precedence than relational operators (they will be evaluated after)
• NOT has the same precedence as negation.

 Operator Meaning Kind && AND Binary || OR Binary ! NOT Unary

Logical Operator Practice

• 2 > 3 && 4 < 5
• false – first operand is false
• 2 < 3 && 4 < 5
• true
• 2 > 3 || 4 < 5
• true
• 2 > 3 || 4 > 5
• false – both operands are false
• !(2 > 3)
• true – operand is false

# Partner Sites

## SqliteTutorials.com

### Stuff I use to make videos

Apple MacBook Pro - http://amzn.to/2AC0WG2

Ubuntu notebook - https://amzn.to/2GE4giY

Desktop - http://amzn.to/2zct252

Microphone - http://amzn.to/2AC1kV0

notebook mouse - http://amzn.to/2BmeZ2d

Screen Recording Software – Camtasia

### Online Courses to learn

Java - https://bit.ly/2H6wqXk

AngularJS - https://bit.ly/2qebsLu

Python- https://bit.ly/2Eq0VSt

Android - https://bit.ly/2qaRSAS

Linux - https://bit.ly/2IwOuqz

AWS Certified Solutions Architect - https://bit.ly/2JrGoAF

Modern React with Redux- https://bit.ly/2H6wDtA

MySQL - https://bit.ly/2qcF63Z