The common control structures are if, for, and while.
Control the structure function?
is the function a control structure?
At the CPU level, there are some jump statements.
In other languages, control statements are more basic. The function is composed of control statements.
In Scala, functions are more fundamental, and closures created with functions can implement all control structures.
(Closures are a big topic, word: Closures can say we see traces of wind)
The implementation of the while expression
def wh (p: = = Boolean) (s: = = Unit) {if (p) {s; WH (P) (s)}} var i = 0; var sum = 0; WH (i <) {i + = 1 sum + = i} println (sum)
You can see that the IF expression is more basic because the while statement depends on it. So how do you implement an if expression?
(Note: The statement has no return value, the expression has a return value, Scala if,while is an expression)
Slow product Scala 1 custom control structure