November 2018
Intermediate to advanced
388 pages
9h 5m
English
A statement is an element of a program that represents an action. An expression is a part of the statement that gets evaluated to a value. Statements introduce mutability. The more statements a program contains, the more mutability it will have. Mutability in code increases the chance that it is erroneous. Expressions, on the other hand, do not produce mutability. In purely functional constructs, there are no statements, there are only expressions. More expressions in a program mean less mutability and code that is more concise.
Consider the code for 5_Expressions.kts:
val number = 5val evenOrOdd = if(number % 2 == 0) "is even number" else "is odd number"println("$number $evenOrOdd")
The output is as follows:
Read now
Unlock full access